What Is a State Machine?#
A finite state machine is the most general form a sequential circuit can take. It is defined by three things: a finite set of states, a rule for choosing the next state from the current state and the inputs, and a rule for producing outputs. Anything that has to remember where it is and act on what happens next — a controller, a protocol handler, a vending machine — is a state machine.
Three Pieces#
Every FSM decomposes into the same three blocks: a state register of flip-flops holding the current state, next-state logic (combinational gates) that computes the state to move to, and output logic that produces the outputs. On each clock edge the register adopts the next state, and the whole thing steps forward.
The feedback from the state register back into the next-state logic is the whole point: the machine’s behavior depends on where it already is, not just on the present input. That loop is the same cross-coupled memory that underlies all sequential logic, organized here into named states.
The Simplest One Is a Counter#
A synchronous counter is a state machine with the plainest possible rule: its next state is always the current state plus one, and it ignores its inputs. Add input-dependent branching — “advance only if the coin input is high,” “jump to the error state on a fault” — and the same structure becomes a general controller. Everything from a counter to a CPU’s control unit is this block diagram with a different next-state rule.
How the outputs are generated (Moore vs. Mealy), how the behavior is captured (state diagrams), and how the states are assigned to bit patterns (state encoding) are the three decisions that turn this general idea into a specific machine.