Recommended Free Tools
A state machine is a way to describe how something behaves: it has a current state, receives an event or input, and follows a rule that determines what happens next. Think of it as “where the system is now + what just happened = what it does next.”
How a state machine works
Imagine a simplified login flow with two states: Logged out and Logged in. The system’s response depends on both the event it receives and its current state.
| # | Preview | Product | Price | |
|---|---|---|---|---|
| 1 |
|
ISE Programmable Logic Controllers | $90.00 | Buy on Amazon |
| 2 |
|
Programmable Logic Controllers: Principles and Applications | $142.03 | Buy on Amazon |
| 3 |
|
Programmable Logic Controllers | $176.88 | Buy on Amazon |
| 4 |
|
McGraw-Hill Education Programmable Logic Controllers | $27.17 | Buy on Amazon |
| 5 |
|
Programmable Logic Controllers | $153.48 | Buy on Amazon |
As an Amazon Associate I earn from qualifying purchases.
| Current state | Event | Next state |
|---|---|---|
| Logged out | Login succeeds | Logged in |
| Logged out | Login fails | Logged out |
| Logged in | Logout | Logged out |
The failed-login row is a transition back to the same state: an event can happen without changing the state. This is a teaching example, not a tested login program.
The three essential pieces
- State: the current mode or situation that matters to what the system should do. “Logged in” matters because it changes which actions make sense.
- Input or event: something the system receives, such as a button press, message, or successful login result.
- Transition: the rule mapping a current state and an input to what state comes next. Some systems also attach conditions or actions to transitions.
NIST’s formal definition of a finite-state machine includes a set of states, a start state, an input alphabet, and a transition function that selects the next state from the current state and input (NIST, “Finite state machine,” modified April 3, 2024). A state diagram usually draws states as circles and transitions as arrows; the event or condition is written beside an arrow (MDN Web Docs, “State machine,” modified July 11, 2025).
#1 Best Overall
Why bother modeling behavior this way?
When a system has distinct modes, ordinary conditional logic can become hard to follow: the same event may need different handling depending on what happened earlier. A state machine makes those valid paths explicit. A diagram or transition table can help someone inspect which events are allowed from each state and what they lead to.
That structure is useful for event-driven behavior, including workflows, software interfaces and protocols, robots, and game characters. For example, Apple’s GameplayKit documents game characters moving among Chase, Flee, Dead, and Respawn states, and a turret moving among Ready, Firing, and Cooldown (Apple Developer Documentation, “GKStateMachine”). Microsoft describes workflow models in terms of states, triggers, conditions, and transitions (Microsoft Learn, “State Machine Workflows — .NET Framework,” updated September 15, 2021); MathWorks also documents applications such as car transmissions, robotics, and telecommunications (MathWorks, “Model a Finite State Machine,” R2026b documentation).
A state machine is a model or way to organize behavior—not a claim that a computer literally contains circles and arrows. It can clarify behavior with distinct modes, but it is not automatically simpler for every small task and does not replace every conditional.
What “finite,” “deterministic,” and other variants mean
These terms describe different properties of a state machine rather than changing the basic idea of states and transitions.
Rank #3
Finite and deterministic
A finite-state machine has a finite set of states. In a deterministic finite machine, a given state and input select one next state. A nondeterministic machine can allow multiple possible next states for the same state and input; the exact meaning of that possibility depends on the model being used (NIST; MDN Web Docs).
Mealy and Moore machines
Mealy and Moore machines differ in where outputs are associated: a Mealy machine associates outputs with transitions, while a Moore machine associates outputs with states. This distinction is about output behavior, not how many next states an input may allow (NIST).
Rank #4
- Programmable Logic Controllers | 6th Edition
- ABIS_BOOK
Hierarchical state machines
When a behavior has many related substates, they can be nested beneath a broader parent state. Shared behavior can be defined once at the parent level, while substates handle their differences. This can reduce repetition in a larger model; for a tiny login example, the extra hierarchy would add little value (Quantum Leaps / QP Framework, “QP/C++ User Manual,” section 3.7, “State Machines”).
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




