Finite State Machines (FSM): Moore and Mealy Machines Explained
Many digital systems need to do more than simply calculate an output from an input. They must remember what happened previously and use that information to decide what to do next.
A traffic-light controller, vending machine, elevator controller, communication protocol, sequence detector, and processor control unit are all examples of systems that operate this way.

The fundamental model used to design such systems is the Finite State Machine (FSM).
A finite state machine represents a digital system using a finite number of states and defined transitions between those states. At any moment, the system occupies one state. Based on its current state and input, it determines its next state and, depending on the FSM model, its output.
The fundamental relationship is:
This article builds on the previous discussion of sequential-circuit design and explains FSMs from fundamentals through practical design, including Moore machines, Mealy machines, state diagrams, state tables, state encoding, sequence detection, state minimization, and implementation using flip-flops.
Table of Contents
1. What Is a Finite State Machine?
A Finite State Machine, or FSM, is a mathematical and hardware model used to represent a system that can exist in a finite number of distinct states.
An FSM consists primarily of:
- Inputs
- Outputs
- States
- State-transition rules
- Memory elements
- Next-state logic
- Output logic
A simplified representation is:
The state is stored using flip-flops.
2. Why Do We Need FSMs?
Consider a traffic-light controller.
The controller cannot decide its next action based only on the current sensor input. It also needs to know what phase of the traffic cycle it is currently in.
For example:
The controller therefore needs memory.
This is exactly the type of problem an FSM solves.
Other examples include:
- Vending machines
- Elevators
- Traffic lights
- Washing machines
- Digital locks
- Serial-data detectors
- Communication controllers
- CPU control units
- Protocol controllers
3. The Basic FSM Model
A synchronous FSM can be viewed as three major sections:
┌─────────────────────┐
Inputs ────────────►│ Next-State Logic │
└──────────┬──────────┘
│
▼
┌───────────┐
┌───►│ Flip-Flops│
│ └─────┬─────┘
│ │
│ ▼
│ Present State
│ │
│ ▼
│ ┌─────────────┐
└────│ Output Logic│────► Output
└─────────────┘
The flip-flops provide the memory required to store the current state.
The combinational logic determines:
where:
- = present state
- = next state
- = input
For the output:
or:
depending on the FSM type.
4. What Is a State?
A state represents the condition or history of the system that is relevant to its future behavior.
For example, a vending machine might have states such as:
IDLE
COIN INSERTED
PRODUCT SELECTED
DISPENSING
These states represent what the controller currently knows about the system.
A state does not necessarily correspond to a physical component. It is an abstraction used to describe the system’s behavior.
5. Number of States and Flip-Flops
If an FSM has states, the number of binary state bits required with ordinary binary encoding is:
For example, four states require:
Therefore:
Six states require:
Therefore:
because:
possible binary combinations are available.
6. FSM State Diagram
A state diagram provides a graphical representation of the FSM.
Each state is represented by a circle, while arrows represent transitions.
For example:
┌─────────┐
│ S0 │
└────┬────┘
│
│ X=1
▼
┌─────────┐
│ S1 │
└────┬────┘
│
│ X=0
▼
┌─────────┐
│ S2 │
└─────────┘
The arrows describe how the machine moves from one state to another.
7. State Transition
A state transition occurs when the system moves from its present state to a new state.
For example:
means that when the machine is in and:
the next state becomes:
At the next active clock edge, the flip-flops store the new state.
8. State Table
The same FSM can be represented using a state table.
A typical table contains:
| Present State | Input | Next State | Output |
|---|---|---|---|
| 0 | — | ||
| 1 | — | ||
| 0 | — | ||
| 1 | — |
The exact output column depends on whether the FSM is Moore or Mealy.
9. Two Major Types of FSMs
There are two classical FSM models:
and:
The fundamental difference is how the output is generated.
10. Moore Machine
In a Moore machine, the output depends only on the present state.
Therefore:
The current input does not directly determine the output.
The output changes when the state changes.
11. Moore Machine Structure
Conceptually:
Input
│
▼
┌─────────────────┐
│ Next-State Logic│
└────────┬────────┘
│
▼
┌──────────┐
│ Flip-Flops│
└────┬─────┘
│
▼
Present State
│
▼
┌────────────┐
│Output Logic│
└─────┬──────┘
│
▼
Output
The output logic receives the state but not the external input directly.
12. Moore State Diagram
In a Moore FSM, outputs are normally written inside the state.
For example:
┌─────────┐
│ S0 / 0 │
└─────────┘
means:
Another state might be:
┌─────────┐
│ S1 / 1 │
└─────────┘
meaning:
13. Mealy Machine
In a Mealy machine, the output depends on both the present state and the current input.
Therefore:
The output is associated with transitions rather than states.
14. Mealy Machine Structure
Conceptually:
┌────────────────┐
Input ──────────►│ Next-State Logic│
│ └───────┬────────┘
│ │
│ ▼
│ ┌──────────┐
│ │Flip-Flops│
│ └────┬─────┘
│ │
│ ▼
└──────────────► Output Logic ─────► Output
The output logic receives both:
and:
15. Mealy State Diagram
For a Mealy machine, transitions are commonly labeled:
For example:
S0 ─── 1/0 ───► S1
means:
causes:
while:
for that transition.
16. Moore vs Mealy
| Feature | Moore | Mealy |
|---|---|---|
| Output depends on | Present state | Present state + input |
| Equation | ||
| Output attached to | States | Transitions |
| Response | State dependent | Can respond directly to input |
| State count | May require more states | May require fewer states |
| Output behavior | Often easier to reason about | Can be more responsive |
| Typical concern | Additional states | Input-related output timing |
Neither model is inherently superior. The appropriate architecture depends on the system requirements.
17. Simple Moore Example
Consider an FSM with two states:
and:
Suppose:
- has output
- has output
and the input controls the transition.
The state behavior could be:
The output is determined solely by the state:
Thus:
with a suitable state encoding.
18. Simple Mealy Example
Suppose the same two states are used, but the output is generated when a particular input occurs.
For example:
Here:
causes the output:
while the machine transitions to .
The output therefore depends on both state and input.
19. Why Mealy Machines Can Use Fewer States
Suppose a particular output needs to occur only during a transition.
A Mealy machine can place that output directly on the transition.
A Moore machine may require a separate state to represent the output condition.
Therefore, in some designs:
But fewer states do not automatically mean a better design. Timing, output glitches, verification complexity, and implementation requirements must also be considered.
20. FSM Design Procedure
A professional FSM design usually follows a systematic process.
Step 1 — Define the specification
Determine:
- Inputs
- Outputs
- Required behavior
- Timing
- Reset conditions
Step 2 — Identify states
Determine what information must be remembered.
Step 3 — Choose Moore or Mealy
Decide how outputs should be generated.
Step 4 — Draw the state diagram
Define all required transitions.
Step 5 — Create the state table
Convert the diagram into a structured table.
Step 6 — Assign binary state codes
Encode each state.
Step 7 — Select flip-flops
D, JK, or T flip-flops can be used.
Step 8 — Derive next-state equations
Determine the logic required for each state bit.
Step 9 — Derive output equations
Determine the required output logic.
Step 10 — Simplify the equations
Use Boolean algebra or K-maps.
Step 11 — Implement and verify
Check every state, transition, output, reset condition, and timing requirement.
21. State Encoding
Suppose we have four states:
One possible binary assignment is:
| State | |
|---|---|
| 00 | |
| 01 | |
| 10 | |
| 11 |
The state encoding determines the values stored in the flip-flops.
Different encoding strategies can be used depending on the technology and design objectives.
22. Binary State Encoding
Binary encoding uses approximately:
state bits for states.
For example, eight states require:
bits.
Therefore:
can represent:
23. One-Hot Encoding
Another approach is one-hot encoding.
With one-hot encoding, each state is represented by a separate flip-flop.
For four states:
Therefore:
instead of two.
This uses more flip-flops but can simplify the next-state logic and is commonly useful in FPGA-based designs.
24. State Reduction
Two states may sometimes be equivalent from the external system’s perspective.
If two states produce identical outputs and equivalent future behavior for every possible input, they may be candidates for merging.
This process is called:
The objective is to reduce the complexity of the FSM without changing its externally observable behavior.
25. Sequence Detector
One of the classic FSM applications is a sequence detector.
Suppose a serial input stream is:
and the system must detect the sequence:
The FSM needs to remember how much of the sequence has already been received.
Possible conceptual states are:
S0 → Nothing matched
S1 → 1 detected
S2 → 10 detected
S3 → 101 detected
When the final required bit arrives, the FSM generates a detection output.
26. Sequence Detector Example
Suppose the input sequence is:
1 0 1
The FSM can progress as:
then:
then:
At , the sequence:
has been detected.
This example demonstrates why memory is required: the circuit must remember previous input bits.
27. Overlapping Sequence Detection
An advanced sequence detector may allow overlapping patterns.
For example:
10101
contains overlapping occurrences of:
The FSM must determine whether part of the detected sequence can simultaneously serve as the beginning of another sequence.
This requires carefully designed state transitions.
It is an excellent example of why state diagrams are useful.
28. FSMs and Flip-Flops
The FSM’s state is physically stored using flip-flops.
Suppose an FSM requires two state bits:
Then two flip-flops store the present state.
The combinational logic calculates:
and:
before the next active clock edge.
At the clock edge:
The process repeats every clock cycle.
29. FSM Using D Flip-Flops
D flip-flops are especially convenient for FSM implementation.
Since:
the next-state equations directly become the D inputs.
For a two-bit FSM:
The implementation therefore becomes:
Next-State Logic
│
├────► D1 ──► Flip-Flop ──► Q1
│
└────► D0 ──► Flip-Flop ──► Q0
30. FSM Using JK Flip-Flops
JK flip-flops can also implement FSMs.
The required and values are determined using the JK excitation table.
| Q | J | K | |
|---|---|---|---|
| 0 | 0 | 0 | X |
| 0 | 1 | 1 | X |
| 1 | 0 | X | 1 |
| 1 | 1 | X | 0 |
The designer uses this table to determine the logic driving each JK input.
31. FSM Using T Flip-Flops
For T flip-flops:
Therefore, once the desired transition is known:
This provides the required toggle logic.
32. Output Logic
The output equations depend on the FSM model.
Moore
Mealy
For multiple outputs:
and so on.
33. Reset in an FSM
An FSM should normally have a defined starting state.
For example:
If the system powers up in an unintended state, its behavior may become unpredictable.
Reset ensures that the machine starts from a known condition.
34. Unused States
Suppose an FSM has six valid states but uses three flip-flops.
Three flip-flops provide:
possible binary states.
Therefore:
states are unused.
The designer should decide what happens if the machine enters one of these states.
A robust FSM can be designed so that an unused state transitions back to a valid state.
35. Synchronous FSM Timing
A typical synchronous FSM operates in this cycle:
The combinational logic must settle sufficiently before the next sampling edge.
A simplified timing requirement is:
Real implementations additionally consider clock skew, jitter, routing delays, and timing margins.
36. FSM vs Counter
Counters are themselves sequential circuits, but not every FSM is a counter.
A binary counter follows a numerical sequence:
An FSM can follow an arbitrary sequence based on inputs.
For example:
The transition may depend on external conditions.
Therefore:
37. FSM Applications
FSMs are fundamental to many digital systems.
Control Units
Processors use control logic to coordinate operations.
Communication Protocols
FSMs can represent protocol states such as:
Traffic Controllers
States represent:
Vending Machines
States represent inserted money, selection, dispensing and change.
Sequence Detectors
FSMs recognize specific binary patterns.
Embedded Controllers
FSMs control the behavior of hardware devices.
38. Common FSM Design Mistakes
Mistake 1 — Missing a transition
Every relevant state/input combination should have defined behavior.
Mistake 2 — Confusing Moore and Mealy outputs
Remember:
Mistake 3 — Forgetting reset
An FSM should normally have a defined startup state.
Mistake 4 — Ignoring unused states
Unused binary combinations should be handled deliberately.
Mistake 5 — Incorrect state encoding
The assigned binary values must be used consistently throughout the state table and equations.
Mistake 6 — Ignoring timing
A logically correct FSM can still fail if its timing constraints are violated.
39. Professional FSM Design Workflow
The entire process can be summarized as:
SYSTEM REQUIREMENT
↓
INPUTS + OUTPUTS
↓
DEFINE STATES
↓
CHOOSE MOORE / MEALY
↓
STATE DIAGRAM
↓
STATE TABLE
↓
STATE ENCODING
↓
SELECT FLIP-FLOPS
↓
EXCITATION TABLE
↓
NEXT-STATE EQUATIONS
↓
OUTPUT EQUATIONS
↓
LOGIC SIMPLIFICATION
↓
HARDWARE IMPLEMENTATION
↓
TIMING ANALYSIS
↓
VERIFICATION
This workflow converts a high-level behavioral requirement into an implementable sequential digital circuit.
40. Important FSM Equations
General Next-State Function
Moore Output
Mealy Output
Required Binary State Bits
D Flip-Flop
T Flip-Flop
JK Flip-Flop
Typical Clock Constraint
41. Quick Revision
What is an FSM?
A sequential model containing a finite number of states and defined transitions.
What stores the state?
Flip-flops or other memory elements.
What determines the next state?
The next-state combinational logic.
What is a Moore machine?
An FSM where:
What is a Mealy machine?
An FSM where:
How many flip-flops are needed for binary-encoded states?
What is state reduction?
Combining equivalent states while preserving the external behavior of the FSM.
Conclusion
Finite State Machines provide a systematic way to design digital systems that must remember, make decisions, and respond according to their previous history.
The central concept is:
The state is stored in flip-flops, while combinational logic determines the next state and output.
The two fundamental FSM models are:
and:
Once state diagrams, state tables, state encoding and next-state equations become familiar, you can design much more complex digital controllers—from simple sequence detectors to processor control units.
Next in the series: Memory in Digital Electronics — RAM, ROM, SRAM, DRAM, EEPROM, Memory Organization and Addressing, where we move from flip-flop-level storage to practical semiconductor memory systems.


