Skip to content
digiwleeaLearn
Open the lab →

D flip-flop

Master and slave

6 min read

A D flip-flop captures the value of its D input at one instant, the rising edge of the clock, and holds it until the next edge. It is built from two D latches in opposite phases (master and slave), which stops the transparency that lets glitches corrupt a plain latch.

Build it in the lab →
The D latch fixed the forbidden-input problem but left a new one: while EN is high it is transparent, so noise on D flows straight to Q. A clocked computer wants to capture D at one precise instant, not stay open for half a cycle. The fix is to chain two D latches so they are never open at the same time, using a NOT to give them opposite enables. Build one live, master and slave latch included, in the D flip-flop circuit.

Master and slave

Connect two D latches in series. The first is the master, the second the slave; the master's Q feeds the slave's D. Invert the clock into the master so the two latches see opposite enables:
master EN = CLK'
slave EN = CLK
When CLK=0 the master is open and sampling D while the slave is closed and holding. When CLK=1 the master closes, freezing whatever D was, and the slave opens and passes that frozen value to Q. The two open-windows never overlap, so D reaches Q only by being captured at the changeover: the rising edge. Built from nothing but NAND gates, the whole flip-flop is nine gates: see the live D flip-flop using NAND gates. Two D flip-flops in a row also make a clean edge detector, which turns any change of an input into a one-clock pulse.

D flip-flop truth table

Put together, the whole behavior fits in three rows. Q+ is the value Q takes after the clock event and Q' is the inverted output most flip-flops also provide.
CLKDQ+ (next state)Q'+
rising edge00 (reset)1
rising edge11 (set)0
no rising edgeXQ (hold)Q' (hold)
On a rising clock edge Q takes whatever D is at that instant; at any other time (clock steady at 0 or 1, or falling) D is ignored and Q holds. Unlike the SR latch there is no forbidden input: a single data line cannot ask for set and reset at once.
Because the next state never depends on the current one, the characteristic equation is the shortest of any flip-flop, and the excitation table is just as simple: to reach a wanted next state, set D to it.
Q+ = D

Behavior across clock edges

  1. Before the first rising edge (CLK=0): master follows D, slave is closed and has never been written, so Q reads Z (undefined).
  2. CLK rises (first edge): master closes, capturing D at that instant; slave opens and passes it through. Q takes a defined value for the first time.
  3. CLK high, D changes: master is closed, so D does nothing; the slave's input is the frozen master value. Q does not move.
  4. CLK falls: slave closes, holding Q; master reopens and starts tracking D again.
  5. CLK rises again (second edge): master closes on the new D, slave passes it through, Q updates. This is the only moment Q can change.
Edge-triggering means exactly one moment per cycle can change Q: the rising edge of CLK. Glitches on D the rest of the cycle are invisible. That predictability is why every register in every processor is built from flip-flops, not bare latches.
An analogy: the D latch is a window you hold open; a flip-flop is a camera shutter. It takes one snapshot of D at the rising edge and holds that picture until the next edge, ignoring everything that happens to D in between. A latch watches continuously; a flip-flop samples at one instant. That instant is what makes synchronous design predictable.
Positive-edge D flip-flop from two D latches; the NOT on CLK keeps master and slave from ever being open together. Open it in the lab and pulse CLK to watch the capture.
Try it
Hold D = 1 and pulse the clock once: Q becomes 1. Now, with CLK high, change D to 0 (no new rising edge). Does Q change? When is the next moment Q can move?
This is the universal storage element of synchronous design. Your CPU's accumulator, its program counter (which flip-flop holds which instruction address), and its instruction register are all banks of these, every one ticking on the same clock. The next lesson gives a flip-flop the one feature a register still needs: the ability to not change.
Probe Q right after power-up, before the first edge, and you will see Z. Expected: the master has seen D but the slave has not yet transferred anything out. The first rising edge initializes Q.

Frequently asked

What is a D flip-flop?

A D flip-flop captures the value of its D input at one instant, the rising edge of the clock, and holds it until the next edge. It is the standard storage element of synchronous logic.

What is the truth table of a D flip-flop?

On a rising clock edge, D = 0 gives Q = 0 and D = 1 gives Q = 1; with no rising edge, D is ignored and Q keeps its value. Its characteristic equation is Q+ = D, and it has no forbidden input combination.

How is a D flip-flop built from D latches?

From two D latches in series with opposite enables (a NOT inverts the clock into the first). The master samples D while CLK = 0; the slave passes the captured value out while CLK = 1. The two open windows never overlap, so D reaches Q only at the changeover edge.

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

A D latch is transparent: while enabled, Q follows D continuously, so glitches pass through. A D flip-flop is edge-triggered: Q can change only at one instant per cycle, the rising clock edge, and ignores D the rest of the time.

Why does Q read Z before the first clock edge?

On power-up the slave latch has never been written, so its output is undefined (Z). The master has seen D, but nothing has transferred through yet. The first rising edge initializes Q to a defined value.

Why is the D flip-flop called a delay flip-flop?

Because Q only takes on the value D had at the clock edge, the output reproduces the input delayed until the next edge: D stands for both data and delay. Chain flip-flops together and each stage hands its value to the next exactly one clock period later, which is precisely the one-cycle-per-stage delay a shift register is built on.

How do you reset or clear a D flip-flop?

Real flip-flops (like the classic 7474) add asynchronous preset (PRE) and clear (CLR) inputs: assert CLR and Q is forced to 0 immediately, assert PRE and Q is forced to 1, regardless of the clock or D. On the 7474 both pins are active-low (drawn with bubbles on the symbol), so hold them at 1 during normal clocked operation, and never assert both at once, which is the same forbidden condition as S = R = 1 in an SR latch. Reset and initialization covers when a design should use these versus a synchronous reset.

You've got the theory. Now try it in the lab and watch it work.

Build it in the lab →Or test yourself: the free placement exam takes 15 minutes →
Found this useful? Share itShare on X
Written by Taceddin SancakCreator of digiwleea. These lessons and the switch-level simulator every diagram runs on grew out of one goal: understand computers from the transistor up by building one.