How to build a D latch from logic gates
A gated D latch stores one bit: while the enable input EN is 1 the output Q follows the data input D, and when EN drops to 0, Q holds the last value. It is an SR latch with two AND gates and a NOT in front.
The plain SR latch remembers a bit but has a forbidden input (S and R both 1) and two separate control lines. The D latch fixes both: one data line D decides what to store, and one enable line EN decides when. The AND gates make sure S and R can never both be 1, so the forbidden case simply cannot happen. The live circuit starts transparent (EN = 1), so Q follows D straight away; turn EN off and Q freezes.
Open this circuit in the lab →
What you need
- 2× NOR: cross-coupled into the SR latch that holds the bit
- 2× AND: S = D AND EN and R = (NOT D) AND EN, so the latch only listens while enabled
- 1× NOT: inverting D for the reset side
Step by step
- Build an SR latch from two cross-coupled
NORgates. The NOR fed by R givesQ; the NOR fed by S givesQ̄(Q-bar). - Place a data input
Dand an enable inputEN. - Make the set signal:
ANDD with EN and wire it to the latch's S input. - Make the reset signal: invert D with a
NOTgate,ANDit with EN, and wire it to the latch's R input. Now S and R are never 1 together. - Probe
QandQ̄. With EN = 1, toggle D and Q follows. Set EN = 0 and toggle D again: Q stays put. That is the stored bit.
D latch truth table
| EN | D | Q (next) |
|---|---|---|
| 0 | x | hold |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
While enabled the latch is transparent: Q is a copy of D, and any change on D passes straight through. While disabled it is opaque and holds. That level-sensitive behaviour is the difference from a D flip-flop, which samples D only at a clock edge; a flip-flop is two of these latches back to back.
You can also read the full theory in the lesson on the gated D latch. 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
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 in the lab →Frequently asked
How does a gated D latch work?
Two AND gates turn D and EN into the set and reset inputs of an SR latch. While EN is 1, D = 1 sets the latch and D = 0 resets it, so Q follows D. While EN is 0, both AND outputs are 0, which is the SR latch's hold state, so Q keeps its value.
What is the difference between a D latch and a D flip-flop?
A D latch is level-triggered: Q follows D for the whole time EN is high. A D flip-flop is edge-triggered: it captures D only at the clock's rising (or falling) edge and ignores D the rest of the time. A D flip-flop is built from two D latches enabled on opposite clock levels.
Why does the D latch not have a forbidden state?
Its S input is D AND EN and its R input is NOT D AND EN. D and NOT D can never both be 1, so S and R can never both be 1, which is the SR latch's forbidden combination.
How many gates does a D latch need?
This one uses five: two NOR gates for the SR latch, two AND gates and one NOT. A version with four NAND gates plus an inverter (or four NANDs with D and NOT D) is also common, since an SR latch can be built from cross-coupled NANDs.