The short answer

A Mealy machine produces its output from both the current state and the current input, so the output is written on the transitions and can change the moment the input changes. A Moore machine produces its output from the current state alone, so the output is written inside each state and only changes after a state transition. Mealy machines react one clock earlier and usually need fewer states; Moore machines have steadier, glitch-resistant outputs that are easier to design.

Mealy and Moore machines are the two classic models of a finite state machine that produces output — the building blocks behind sequence detectors, vending machines, traffic controllers and almost every digital control circuit. They recognise the same problems and store the same state. The single thing that separates them is what the output depends on.

In a Mealy machine the output is a function of the state and the input together. In a Moore machine the output is a function of the state only. That one difference changes how the state diagram is drawn, how many states you need, how fast the output reacts, and how prone the circuit is to glitches.

This guide builds both models from their formal definitions, walks through the same 101 sequence detector designed each way, shows how to convert between them, and covers the timing, applications and exam points that come up most often.

Two-panel diagram comparing a Mealy machine with outputs on its transitions and a Moore machine with outputs inside its states
A Mealy machine labels output on each transition (input/output); a Moore machine labels output inside each state.

Finite State Machines in Brief

A finite state machine, or FSM, is a model with a finite set of states, a defined start state, and rules that move it from one state to another as it reads input. Mealy and Moore machines are the two FSMs that also produce output, which is why they are called transducers. They differ from the DFA and NFA, which only accept or reject a string rather than emit an output symbol at each step.

In hardware terms, both are sequential circuits: a block of memory (flip-flops) holds the state, and a block of combinational logic computes the next state and the output. The only structural question is whether the output logic reads just the state register, or the state register and the input together.

The Mealy Machine

A Mealy machine produces output from the current state and the current input. Because the input takes part in the output, the output is attached to the transitions of the state diagram and is written in input / output form on each arrow.

Formally, a Mealy machine is a six-tuple (Q, q0, Σ, O, δ, λ):

  • Q — a finite set of states
  • q0 — the start state
  • Σ — the input alphabet
  • O — the output alphabet
  • δ: Q × Σ → Q — the next-state (transition) function
  • λ: Q × Σ → O — the output function, which reads state and input

The output function is the defining feature: λ takes both arguments. A classic example is a vending machine that releases a product the instant the final coin is inserted — the action depends on the running total (state) and the coin just added (input), not on waiting for the next clock tick.

Advantages
  • Fewer states — often needs fewer states than a Moore machine for the same task.
  • Faster response — output reacts in the same cycle as the input, one step ahead of Moore.
  • Fine-grained output — different inputs from one state can give different outputs.
Disadvantages
  • Glitch-prone — output can change asynchronously with the input, so input noise can ripple through.
  • Harder to design — transition-based output is trickier to reason about and debug.
  • Timing-sensitive — output is not registered, so it must be sampled carefully.

The Moore Machine

A Moore machine produces output from the current state alone. The input has no direct part in the output, so the output is attached to the states and is written inside each node in state / output form. The output stays constant for as long as the machine sits in a state and changes only when it moves to a new one.

Formally, a Moore machine is also a six-tuple (Q, q0, Σ, O, δ, λ), and only the output function differs:

  • δ: Q × Σ → Q — the next-state function, same as Mealy
  • λ: Q → O — the output function, which reads the state only

A traffic-light controller is the textbook example: the lights shown depend purely on which state the controller is in (green, yellow or red), and they change only when the controller transitions to the next state on a timer.

Advantages
  • Stable, glitch-free output — output changes only on a state transition, synchronised to the clock.
  • Easier to design — one output value per state is simple to reason about and verify.
  • Safer in synchronous systems — predictable timing makes it the default for clocked control logic.
Disadvantages
  • More states — often needs an extra state per distinct output value.
  • One cycle slower — output appears a clock tick after the input that caused it.
  • Less granular — a single state cannot give two different outputs for two inputs.

Worked Example: A 101 Sequence Detector

The clearest way to see the difference is to build the same circuit both ways: a detector that outputs 1 whenever it has just seen the pattern 101 in a bit stream (overlapping matches allowed). The Mealy design needs three states; the Moore design needs four. That extra state is the price Moore pays for tying output to states.

Mealy version (three states)

Output is shown as part of each transition. Detection happens on the arrow leaving S2 on input 1.

Mealy machine state diagram detecting the sequence 101 using three states with output labelled on each transition in input slash output format
A Mealy 101 detector needs only three states; the output 1 appears on the S2 to S1 transition on input 1.
Present stateInput = 0 (next state / output)Input = 1 (next state / output)
S0 — no useful prefixS0 / 0S1 / 0
S1 — seen “1”S2 / 0S1 / 0
S2 — seen “10”S0 / 0S1 / 1
Moore version (four states)

Output belongs to the state. A dedicated state S3 carries output 1 to signal a match.

Moore machine state diagram detecting the sequence 101 using four states with the output written inside each state node
A Moore 101 detector needs four states; the output 1 belongs to state S3, not to any transition.
Present stateState outputNext state (input = 0)Next state (input = 1)
S0 — no useful prefix0S0S1
S1 — seen “1”0S2S1
S2 — seen “10”0S0S3
S3 — seen “101”1S2S1

Feed both machines the stream 1 0 1 0 1. The Mealy detector raises its output during the third bit, the moment the second 1 arrives. The Moore detector raises its output on the next clock edge, once it has settled into state S3. Same detections, one cycle apart — that timing offset is the practical heart of the Mealy versus Moore choice.

Converting Between the Two

The two models are equivalent in power: any Mealy machine can be rewritten as a Moore machine and vice versa. Only the state count and output timing change.

Moore to Mealy

Always straightforward and never adds states. Move each state’s output onto every transition that enters that state. The result has the same number of states and reacts one cycle earlier.

Mealy to Moore

May add states. If a Mealy state can be reached by transitions carrying different outputs, split it into one copy per distinct output value so each new state has a single, well-defined output. This is why Moore versions are usually larger.

Mealy vs Moore Machines: Key Differences

AspectMealy MachineMoore Machine
Output depends onCurrent state and current inputCurrent state only
Output functionλ: Q × Σ → Oλ: Q → O
Output shown onTransitions (input / output on the arrow)States (state / output inside the node)
Number of statesUsually fewerUsually more (often one extra per output value)
Output timingReacts in the same cycle as the inputReacts one clock cycle later
Output stabilityCan change asynchronously, more glitch-proneChanges only on state transition, glitch-resistant
Design effortHarder to design and debugEasier to design and verify
Best suited toFast reaction, fine-grained controlStable, predictable, synchronous output
Typical examplesVending machines, protocol controllers, signal processingTraffic lights, elevators, digital clocks

Output Timing and Glitches

The timing difference is the reason the choice matters in real hardware. A Moore output is driven straight from the state register, so it is effectively registered and changes cleanly on the clock edge. That makes it the safe default in synchronous designs where downstream logic samples the output on the same clock.

A Mealy output is combinational logic of the input, so it can change part-way through a clock cycle and can briefly glitch if the input is noisy. The upside is speed: the Mealy output is available a full cycle earlier. A common engineering compromise is to take a Mealy design and pass its output through a flip-flop, which buys the smaller state count while restoring clean, registered timing.

Applications

Where Mealy fits
  • Vending and ticketing machines that act the instant a coin lands
  • Communication and bus protocol controllers
  • Signal-processing blocks needing immediate response
  • Pattern and sequence detectors where state count matters
Where Moore fits
  • Traffic-light and crossing controllers
  • Elevator and lift control systems
  • Digital clocks and timers
  • Any control unit where output stability beats raw speed

GATE Exam Tips

  • Count states carefully. A frequent question asks for the minimum states in a Moore versus a Mealy sequence detector. The Moore version typically needs one more state to hold the output.
  • Know the output functions cold. Mealy is λ(state, input); Moore is λ(state). That single line answers most theory questions.
  • Remember the timing. For the same input, the Mealy output leads the Moore output by one clock cycle.
  • Diagram convention. Output on the arrow means Mealy; output in the circle means Moore.
  • Equivalence. Both accept the same languages and can be converted to each other — conversion never changes computational power, only state count and timing.

Frequently Asked Questions

The output. A Mealy machine computes its output from the current state and the current input, so output is attached to transitions and can change as soon as the input changes. A Moore machine computes its output from the current state alone, so output is attached to states and changes only on a state transition. Everything else about the two models is the same.

The Mealy machine usually needs fewer states. Because its output can depend on the input, a single state can produce different outputs for different inputs. A Moore machine often needs an extra state for each distinct output value, since each state carries exactly one output. The 101 detector is a clear case: three states for Mealy, four for Moore.

The Mealy machine. Its output reacts in the same clock cycle as the input that caused it, because the output logic reads the input directly. A Moore machine’s output appears one clock cycle later, after the machine has transitioned into the state that carries the new output. For the same input sequence, the Mealy output leads the Moore output by one cycle.

Yes. The two models are equivalent, so any Mealy machine has a Moore equivalent and vice versa. Converting Moore to Mealy is direct and never adds states. Converting Mealy to Moore may add states, because a state reached by transitions with different outputs must be split into one copy per output value. Conversion changes the state count and output timing, never the computational power.

Moore machines are generally safer in synchronous systems because their output is driven directly by the state register and changes cleanly on the clock edge, avoiding glitches. Mealy machines are chosen when speed or a smaller state count matters more. A common middle ground is to register a Mealy output through a flip-flop, keeping the smaller design while regaining clean, synchronous timing.

Wrapping Up

Mealy and Moore machines solve the same problems and store the same state. The fork is whether output reads the input alongside the state, or the state alone. That choice decides how the diagram is drawn, how many states you need, and whether the output reacts this cycle or the next.

Reach for a Mealy machine when reaction speed and a tight state count matter, and for a Moore machine when steady, glitch-free output and easy verification matter more. If you remember one line, make it this: output on the transition is Mealy, output in the state is Moore.

Related reading on DiffStudy:

Whatsapp-color Created with Sketch.

By Arun Kumar

Full Stack Developer with a BE in Computer Science, working with React, Next.js, Node.js, MongoDB, and AI/ML tools. Founder of DiffStudy — built to help CS students ace GATE and university exams, and keep developers up to date across AI, cloud, system design, web development, and every field of computer science. Every article is written from real hands-on experience, not just theory.

Leave a Reply

Your email address will not be published. Required fields are marked *


You cannot copy content of this page