Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksToolsOpen the lab →

D latch vs D flip-flop: the difference, live

A D latch is level-triggered: while its clock (enable) is 1 it is transparent and Q follows D, and when the clock is 0 it holds. A D flip-flop is edge-triggered: Q takes D only at the instant the clock rises, and holds it for the rest of the cycle. This live circuit feeds the same D and CLK into both, so you can watch the difference.

Set CLK to 1 and toggle D: the LATCH output follows every change, while FF does not move. Set CLK to 0 and both hold. Raise CLK again and FF copies whatever D is at that moment. The flip-flop here is built from two D latches with opposite enables (the master-slave design of the D flip-flop): the first is transparent while the clock is 0, the second while it is 1, so a value gets all the way through only at the rising edge. That is why registers and counters use flip-flops: with latches, a value could race through several stages during one long high phase, while edge triggering moves every stage exactly one step per clock. Latches are still useful where transparency is wanted, and they are smaller. Here CLK is a plain switch rather than a running clock, so you can hold it high as long as you like. Both outputs start out unknown until CLK first goes high, the way real ones power up in an unknown state. A 14-step sequence (D wiggled with CLK held high, then held low, then rising edges with D at 1 and at 0) is checked on both outputs before the page is built.

Live circuit: click the inputs to toggle them and watch the outputs update. It runs the real simulator, right here on the page.

Open this circuit in the lab →

What you need

Step by step

  1. Place inputs D and CLK and probes LATCH and FF.
  2. Wire D to the data input of both parts, and CLK to the latch's enable and the flip-flop's clock.
  3. Set CLK = 1 so both outputs become defined, then toggle D: LATCH follows each change and FF stays put.
  4. Set CLK = 0 and toggle D: now both hold their values.
  5. Raise CLK again: FF takes the value D has at that instant, and LATCH starts following D again.

The checked sequence, step by step

StepDCLKLATCHFFWhat happens
100 to 100First rising edge: both take D = 0
21110CLK high: the latch follows D, the flip-flop does not
30100The latch follows again
41110And again
511 to 010CLK falls: both hold
60010D changes, nothing else does
710 to 111Rising edge with D = 1: the flip-flop updates
80101The latch follows D, the flip-flop holds its 1
901 to 001Both hold
1000 to 100Rising edge with D = 0

The rows summarize the 14 checked steps (a few repeat a step with D toggled while CLK is 0). The flip-flop changes only in the rows where CLK goes from 0 to 1; the latch changes whenever D does while CLK is 1. More in the lessons on the D latch and the D flip-flop.

You can also read the full theory in the lesson on why a latch is not enough. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.

Build more parts from gates

half adderfull adderhalf subtractorfull subtractor2:1 multiplexer4:1 multiplexerXOR gate from NAND gates2-to-4 decoderSR latchD flip-flopJK flip-flopT flip-flop4-bit shift register4-bit ripple carry adderD latch1-to-4 demultiplexer4-bit magnitude comparator4-bit ring counter4-bit Johnson counter4-to-2 priority encoder4-bit synchronous counter3-to-8 decoder8-to-1 multiplexer4-bit carry lookahead adderhalf adder from NAND gates2-bit comparatorBCD to 7-segment decoder4-bit up/down counterdecade counter2-bit multiplier4-bit ALU4-bit array multiplierNOT, AND, OR and NOR from NANDNOT, OR, AND and XOR from NORfull adder from NAND gatesSR latch from NAND gatesparity generator and checker4-bit adder/subtractorBCD adder4-bit universal shift registermod-6 counter4-bit ripple counterbinary to Gray code converterhalf adder from NOR gatesfull adder from NOR gates4-bit register with parallel load1011 sequence detectorbinary to BCD converterD flip-flop from NAND gates1-bit ALUCMOS inverterCMOS NAND gateCMOS NOR gatePISO shift registerSR flip-flop from NAND gatesBCD to excess-3 code converterHamming (7,4) code encoder and correctortraffic light controller4-bit barrel shifterCMOS AND gateCMOS OR gateCMOS XOR gate1-bit magnitude comparatorhalf subtractor from NAND gatesfull subtractor from NAND gates8-to-3 encoderGray to binary converter4-to-16 decoderfull adder using 4:1 multiplexersedge detectorserial adder4-bit carry-select adder4-bit Kogge-Stone adder4-bit carry-skip adder4x4 Wallace tree multiplier8-bit adderfrequency divider (by 2, 4 and 3)switch debouncer (SR latch)3-bit Gray code counterMealy machine (1011 detector)master-slave JK flip-flop (NAND)half subtractor from NOR gates1-to-8 demultiplexerexcess-3 to BCD code convertervending machine FSM4-bit carry-save adder3-bit synchronous counter (JK)CMOS transmission gatetri-state buffer (CMOS)2-to-1 mux from transmission gatesmod-5 counterflip-flop conversion (JK to D)8-bit ALUdecimal to BCD encoderBCD to decimal decoder4-to-1 mux from 2-to-1 muxesXOR gate from NOR gates4-bit LFSR74LS138 decoderBCD subtractor74181 ALUCMOS AOI gate (AOI21)74LS47 BCD to 7-segment decoder74HC595 shift register7400 quad NAND gate chip7402 quad NOR gate chip7404 hex inverter chip7408 quad AND gate chip7432 quad OR gate chip7486 quad XOR gate chip

Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab, with the free theory reference alongside.

Open the D latch vs D flip-flop in the lab →

Frequently asked

What is the difference between a D latch and a D flip-flop?

A D latch is level-triggered: while its enable is 1, Q follows D continuously. A D flip-flop is edge-triggered: Q changes only at the clock's rising (or falling) edge, taking the value D has at that instant, and ignores D the rest of the time.

What does transparent mean for a latch?

While the enable is active, a latch passes D straight through to Q, as if it were a wire, so every change on D appears on Q. When the enable goes inactive it stops passing and holds the last value.

Why do registers use flip-flops instead of latches?

Because in a chain of storage elements on one clock, transparent latches would let a value run through several stages during a single high phase. Flip-flops sample only at the edge, so every stage moves exactly one step per clock.

Is a flip-flop made of latches?

Often, yes. A master-slave D flip-flop is two D latches in series with opposite enables: the master is transparent while the clock is low, the slave while it is high, so D reaches Q only at the rising edge.

Which is faster, a latch or a flip-flop?

A latch is smaller and passes data with less delay, since it is half of a master-slave flip-flop. Flip-flops are easier to design with, because their outputs change only at clock edges.