G27
Self-checkedTier 1 14 min readdl.latches-flipflops

Latches and flip-flops

The memory elements of digital circuits: the SR latch, the gated and D latch, edge-triggered D, JK and T flip-flops, characteristic tables and equations, the race-around problem, setup and hold times.

Why it exists

A combinational circuit forgets: change the inputs and the old output is gone. Anything that remembers, a register, a counter, the program counter, a finite-state controller, needs a circuit that stores a bit. The basic trick is feedback: connect two gates so that each one's output is the other's input. The loop has two stable states, and it stays in whichever one it was put in. From that single idea come the latch, the flip-flop, and every sequential circuit that follows. GATE asks for the behaviour tables, the characteristic equations, the output waveform for a given clock and input, the difference between a latch and a flip-flop, and the cause of the race-around condition.

Prerequisites

You need the gates of logic gates, in particular NAND and NOR.

Precise definitions

Sequential circuit. A circuit whose outputs depend on the present inputs and on stored state. It is synchronous if the state changes only at the ticks of a clock, and asynchronous otherwise. With nn storage elements it has up to 2n2^n states.

Latch and flip-flop. A latch is level sensitive: while its enable input is active the output follows the data input (it is transparent), and when the enable is inactive it holds. A flip-flop is edge triggered: it looks at its inputs only at a clock edge (rising or falling) and holds the value for the rest of the cycle. In symbols a small triangle on the clock input marks edge triggering, and a bubble before it marks the falling edge.

SR latch (NOR). Two cross-coupled NOR gates: Q=(R+Q′)′Q = (R + Q')' and Q′=(S+Q)′Q' = (S + Q)'.

SSRRnext QQ
00holds
010 (reset)
101 (set)
11forbidden: both outputs 0

When S=R=1S = R = 1 both outputs are forced to 0, so QQ and Q′Q' are no longer complements. If both inputs then return to 0 together the latch races: both gates change at the same moment and the final state is unpredictable. That is why S=R=1S = R = 1 is forbidden.

SR latch (NAND). With cross-coupled NAND gates the inputs are active low: S′=0S' = 0 sets, R′=0R' = 0 resets, S′=R′=1S' = R' = 1 holds and S′=R′=0S' = R' = 0 is forbidden (both outputs 1).

Gated SR latch. Two extra gates make the inputs effective only while an enable EE is 1: Seff=S ES_{eff} = S\,E and Reff=R ER_{eff} = R\,E.

D latch. A gated SR latch with S=DS = D and R=D′R = D', so S=R=1S = R = 1 cannot occur. While E=1E = 1 the output follows DD (transparent), while E=0E = 0 it holds. It can be built from four NAND gates: N1=(DE)′N_1 = (DE)', N2=(EN1)′N_2 = (E N_1)', Q=(N1Q′)′Q = (N_1 Q')', Q′=(N2Q)′Q' = (N_2 Q)'.

D flip-flop (edge triggered). Two D latches back to back, the first (master) transparent while the clock is low and the second (slave) transparent while the clock is high. At the rising edge the master closes holding the value DD had just before the edge, and the slave opens and passes it to the output. So QQ takes the value of DD at the rising edge and holds it for a whole cycle. A direct gate-level version uses six NAND gates (three SR latches). The characteristic equation is Q+=DQ^+ = D (here QQ is the present state and Q+Q^+ the next state).

JK flip-flop. Behaves like an SR flip-flop with the forbidden input given a useful meaning:

JJKKQ+Q^+action
00QQhold
010reset
101set
11Q′Q'toggle

Characteristic equation: Q+=JQ′+K′QQ^+ = JQ' + K'Q.

T flip-flop. Toggles when T=1T = 1 and holds when T=0T = 0: Q+=T⊕Q=TQ′+T′QQ^+ = T \oplus Q = TQ' + T'Q. With T=1T = 1 it divides the clock frequency by 2.

SR flip-flop. Q+=S+R′QQ^+ = S + R'Q with the restriction SR=0SR = 0.

Race-around. A JK latch (level triggered) with J=K=1J = K = 1 toggles over and over for as long as the clock stays high, once per gate delay around the feedback loop, so the output at the end of the pulse depends on the pulse width. Master-slave or edge-triggered construction removes the problem: the output changes only once per clock.

Timing parameters. Setup time tsut_{su}: the data must be stable this long before the active clock edge. Hold time tht_h: it must stay stable this long after the edge. Clock-to-output delay tcqt_{cq}: the time from the edge until QQ is valid. If setup or hold is violated the flip-flop may enter a metastable state, an intermediate output that takes an unpredictable time to resolve.

Asynchronous inputs. Preset (set) and clear (reset) inputs force the output directly, independent of the clock.

How it works

Three animations show how the same ideas look in time. First the SR latch built from two NOR gates, with every output change one gate delay behind its cause. Watch the forbidden case at the end.

SR latch from two NOR gates: Start

Simulated, not typed
SRQQ't = 0

Dashed lines mark rising clock edges. Green is an output, blue a stored state, black an input, grey the clock. One tick = one gate delay.

Step 1

Two NOR gates feed each other: Q = NOR(R, Q') and Q' = NOR(S, Q). With S = R = 0 the circuit has two stable states; this run starts in the reset state Q = 0, Q' = 1.

1 / 6
computed by script: discrete-time simulation of the circuit (gate-level unit delays for latches, ideal edges for flip-flops). python3 scripts/gen-dl-seq-traces.py

Next, a D latch and a D flip-flop driven by the same clock and the same data. The latch follows DD whenever the clock is high; the flip-flop changes only at the rising edge and takes the value DD had just before it.

D latch against D flip-flop: Start

Simulated, not typed
CLKDQ latchQ flip-flopt = 0

Dashed lines mark rising clock edges. Green is an output, blue a stored state, black an input, grey the clock. One tick = one time unit.

Step 1

Same clock and data feed a D latch (level sensitive) and a D flip-flop (edge triggered, made of two latches). Both start at 0.

1 / 7
computed by script: discrete-time simulation of the circuit (gate-level unit delays for latches, ideal edges for flip-flops). python3 scripts/gen-dl-seq-traces.py

With J=K=1J = K = 1 a level-triggered JK latch toggles repeatedly during the high phase (race-around), while an edge-triggered one toggles once per clock.

Race-around with J = K = 1: J = K = 1

Simulated, not typed
CLKQ (level JK latch)Q (edge JK flip-flop)t = 0

Dashed lines mark rising clock edges. Green is an output, blue a stored state, black an input, grey the clock. One tick = one gate delay.

Step 1

Both JK inputs are 1, so every clock pulse should toggle the output once.

1 / 3
computed by script: discrete-time simulation of the circuit (gate-level unit delays for latches, ideal edges for flip-flops). python3 scripts/gen-dl-seq-traces.py

The characteristic equation of the JK flip-flop is just the four rows of its table folded into one expression:

JK flip-flop: the characteristic equation Q+ = JQ' + K'Q

Computed exactly, not typed
JKQJQ'K'QQ+ by the ruleQ+ = JQ'+K'Q
000····
001····
010····
011····
100····
101····
110····
111····

Step 0

Claim: J = K = 0 holds, J = 0 K = 1 resets, J = 1 K = 0 sets and J = K = 1 toggles. One equation, Q+ = JQ' + K'Q, covers all four cases, where Q is the present state and Q+ the next state.

0 / 9
computed by script: exact integer, Fraction and truth-table evaluation (IEEE 754 patterns via Python struct where used), not typed by hand. python3 scripts/gen-dl-traces.py

Worked examples

EX 1Behaviour table of the NOR SR latch, a JK sequence and a T flip-flop

Easy

The program simulates two NOR gates (updating both until nothing changes), then runs a sequence of JK inputs and a T flip-flop with T=1T = 1.

#include <stdio.h>
 
/* NOR-gate SR latch: update both gates until nothing changes */
static void sr_latch(int *q, int *qn, int s, int r) {
    for (int i = 0; i < 10; i++) {
        int q2 = !(r || *qn);
        int qn2 = !(s || *q);
        if (q2 == *q && qn2 == *qn) break;
        *q = q2;
        *qn = qn2;
    }
}
 
static int jk_next(int q, int j, int k) { return (j && !q) || (!k && q); }
 
int main(void) {
    printf("Q S R | Q+ Q'+\n");
    for (int q0 = 0; q0 < 2; q0++)
        for (int s = 0; s < 2; s++)
            for (int r = 0; r < 2; r++) {
                int q = q0, qn = !q0;
                sr_latch(&q, &qn, s, r);
                printf("%d %d %d |  %d  %d%s\n", q0, s, r, q, qn, s && r ? "   forbidden" : "");
            }
    int q = 0;
    int js[] = {1, 1, 0, 0, 1, 1}, ks[] = {0, 1, 0, 1, 0, 1};
    printf("JK sequence from Q = 0:");
    for (int i = 0; i < 6; i++) {
        q = jk_next(q, js[i], ks[i]);
        printf(" %d", q);
    }
    printf("\n");
    int t = 0;
    printf("T = 1 for eight clocks:");
    for (int i = 0; i < 8; i++) {
        t = t ^ 1;
        printf(" %d", t);
    }
    printf("\n");
    return 0;
}
Q S R | Q+ Q'+
0 0 0 |  0  1
0 0 1 |  0  1
0 1 0 |  1  0
0 1 1 |  0  0   forbidden
1 0 0 |  1  0
1 0 1 |  0  1
1 1 0 |  1  0
1 1 1 |  0  0   forbidden
JK sequence from Q = 0: 1 0 0 0 1 0
T = 1 for eight clocks: 1 0 1 0 1 0 1 0

Reading the table. With S=R=0S = R = 0 the latch keeps its state (rows 1 and 5). S=1,R=0S = 1, R = 0 always ends with Q=1Q = 1 (rows 3 and 7), S=0,R=1S = 0, R = 1 ends with Q=0Q = 0 (rows 2 and 6). With S=R=1S = R = 1 both outputs are 0, the forbidden state. JK sequence: JK=10J K = 10 sets, 11 toggles to 0, 00 holds 0, 01 keeps 0, 10 sets, 11 toggles to 0. T flip-flop: the output toggles on every clock, so it is a square wave of half the clock frequency.

EX 2Latch or flip-flop?

Easy

A circuit output follows the data input for the whole time a control line is high. This is a latch (level sensitive). A circuit that samples the data only at the rising edge of a control line and keeps the sampled value for the whole period is a flip-flop (edge triggered). In the animation of the D latch against the D flip-flop, the line "Q latch" copies DD while the clock is high, including the short pulse of DD; "Q flip-flop" ignores that pulse.

EX 3Deriving the JK characteristic equation

Medium

From the table, Q+=1Q^+ = 1 for the cases (J,K,Q)=(0,0,1),(1,0,0),(1,0,1),(1,1,0)(J, K, Q) = (0,0,1), (1,0,0), (1,0,1), (1,1,0). Group them: (1,0,0)(1,0,0) and (1,1,0)(1,1,0) give JQ′JQ'; (0,0,1)(0,0,1) and (1,0,1)(1,0,1) give K′QK'Q. So Q+=JQ′+K′QQ^+ = JQ' + K'Q. The animation checks the equation against the table on all 8 rows.

EX 4Setting and holding with a NAND latch

Medium

A NAND SR latch has active-low inputs. With S′=0S' = 0 and R′=1R' = 1 the output QQ is forced to 1 (set); returning S′S' to 1 leaves Q=1Q = 1. Pulsing R′R' to 0 resets it to 0. With both inputs 0 both outputs are 1, the forbidden state, and the next state after both rise together is unpredictable. A common mistake is to treat the inputs as active high.

EX 5Output waveform of a D flip-flop

GATE level

Given a rising-edge D flip-flop with D=1D = 1 before the first rising edge, DD falling to 0 in the middle of the high phase, and D=1D = 1 again just before the second edge, the output is: 1 after the first edge (the value of DD just before it), still 1 through the high phase (the later change of DD is ignored), and 1 after the second edge. The output only ever changes at a rising edge, and equals DD just before that edge. The same inputs applied to a D latch would make the output fall in the middle of the high phase.

EX 6Counting gates and states

GATE level

(a) A gated D latch needs 4 NAND gates (no inverter, as the construction above shows). An edge-triggered D flip-flop built directly from NAND gates needs 6; built as a master-slave pair of D latches it needs 2×4=82 \times 4 = 8 NAND gates and an inverter for the clock. (b) nn flip-flops can store 2n2^n different states: 5 flip-flops give 32 states, and a state described by 100 different values needs ⌈log⁡2100⌉=7\lceil \log_2 100 \rceil = 7 flip-flops. (c) A T flip-flop with T=1T = 1 driven by a 1 MHz clock gives a 500 kHz output with a 50% duty cycle.

Cheat box

Cheat box

  • Latch = level sensitive (transparent while enabled). Flip-flop = edge triggered.
  • NOR SR latch: 00 hold, 01 reset, 10 set, 11 forbidden (both outputs 0). The NAND SR latch is active low: S′R′=11S'R' = 11 holds, S′=0S' = 0 sets, R′=0R' = 0 resets, S′R′=00S'R' = 00 is forbidden.
  • D: Q+=DQ^+ = D. JK: Q+=JQ′+K′QQ^+ = JQ' + K'Q. T: Q+=T⊕QQ^+ = T \oplus Q. SR: Q+=S+R′QQ^+ = S + R'Q, SR=0SR = 0.
  • JK: 00 hold, 01 reset, 10 set, 11 toggle. T = 1 divides the frequency by 2.
  • Race-around: level-triggered JK with J=K=1J = K = 1 toggles repeatedly while the clock is high. Cure: master-slave or edge triggering.
  • D flip-flop = two D latches (master transparent when clock low, slave when high). Gated D latch = 4 NAND gates; edge-triggered D flip-flop = 6 NAND gates.
  • Setup time before the edge, hold time after; tcqt_{cq} = edge to valid output. nn flip-flops give 2n2^n states.

Traps and GATE patterns

Connections

Conversions between the four flip-flop types are the next topic (flip-flop conversion). Rows of D flip-flops are registers and shift registers, T flip-flops chained are counters, and flip-flops plus combinational logic are state machines. In the processor, registers in the datapath and the control state are exactly these elements, and the clock period limit comes from tcqt_{cq} + logic delay + tsut_{su} (see the instruction cycle).

PYQs

7 previous year questions from your book. I re-solved each one myself (6 by running or simulating, 1 by reasoning only); the book's key is shown next to my answer. All PYQs

GATE 2023 · MCQ · 1 markQ4 · page 184 of the book
The output of a 2-input multiplexer is connected back
to one of its inputs as shown in the figure.

Match the functional equivalence of this circuit to
one of the following options
  • (a)D Flip-flop
  • (b)D Latch
  • (c)Half-adder
  • (d)Demultiplexer
GATE 2017 · Set 2 · MCQ · 2 marksQ9 · page 185 of the book
The next state table of a 2-bit saturating up-counter is
given below.
Q1 Q0 Q1
+ Q0
+
0
0
0
1
0
1
1
0
1
0
1
1
1
1
1
1

DIGITAL LOGIC

The counter is built as a synchronous sequential
circuit using T flip-flops. The expressions for T1
and T0 are
  • (a)T1 = Q0Q1 , T0 = Q'0Q'1
  • (b)T1 = Q'1Q0 , T0 = Q'1 + Q'0
  • (c)T1 = Q1 + Q0 , T0 = Q'1Q'0
  • (d)T1 = Q'1Q0 , T0 = Q1 + Q0
GATE 2017 · Set 1 · MCQ · 2 marksQ10 · page 186 of the book
Consider a combination of T and D flip-flops
connected as shown below. The output of the D
flip-flop is connected to the input of the T flip-flop
and the output of the T flip-flop is connected to the
input of the D flip-flop. Initially, both Q0 and Q1
are set to 1 (before the 1st clock cycle). The outputs
  • (a)Q1Q0 after the 3rd cycle are 11 and after the 4th cycle are 00 respectively
  • (b)Q1Q0 after the 3rd cycle are 11 and after the 4th cycle are 01 respectively
  • (c)Q1Q0 after the 3rd cycle are 00 and after the 4th cycle are 11 respectively
  • (d)Q1Q0 after the 3rd cycle are 01 and after the 4th cycle are 01 respectively
GATE 2015 · Set 1 · MCQQ12 · page 186 of the book
A positive edge-triggered D flip-flop is connected to
a positive edge-triggered JK flipflop as follows. The
Q output of the D flip-flop is connected to both the J
and K inputs of the JK flip-flop, while the Q output
of the JK flip-flop is connected to the input of the D
flip-flop. Initially, the output of the D flip-flop is set
to logic one and the output of the JK flip-flop is
cleared. Which one of the following is the bit
sequence (including the initial state) generated at the
Q output of the JK flip-flop when the flip-flops are
connected to a free-running common clock? Assume
that J = K = 1 is the toggle mode and J = K = 0 is the
state-holding mode of the JK flip-flop. Both the flip-
flops have non-zero propagation delays.
  • (a)0110110..
  • (b)0100100...
  • (c)01110110...
  • (d)011001100...
GATE 2014 · Set 3 · MCQ · 2 marksQ15 · page 187 of the book
The above synchronous sequential circuit built
using JK flip-flops is initialized with Q2Q1Q0 = 000.
The state sequence for this circuit for the next 3
clock cycles is
  • (a)001, 010, 011
  • (b)111, 110, 101
  • (c)100, 110, 111
  • (d)100, 011, 001
GATE 2006 · MCQ · 1 markQ21 · page 188 of the book
You are given a free running clock with a duty
cycle of 50% and a digital waveform f which
changes only at the negative edge of the clock.
Which one of the following circuits (using clocked
D flip-flops) will delay the phase of f by 180°?
GATE 2005 · MCQ · 1 markQ24 · page 189 of the book
Consider the following circuit involving a positive
edge triggered D FF.

Consider the following timing diagram. Let
represents the logic level on the line in the -th clock
period

Let represent the complement of . The correct
output sequence on over the clock periods through
is:
  • (a)A0 A1 A1' A3 A4
  • (b)A0 A1 A2 A3 A4
  • (c)A1 A2 A2' A3 A4
  • (d)A1 A2 A3 A4 A5'

Self-check

Question 1

A JK flip-flop is in state Q=1Q = 1 and receives J=0J = 0, K=0K = 0 and then J=1J = 1, K=1K = 1 at the next two clock edges. What is QQ after each?

Show answer

J=K=0J = K = 0 holds: QQ stays 1. Then J=K=1J = K = 1 toggles: Q=0Q = 0.

Question 2

Write the characteristic equation of a T flip-flop and of an SR flip-flop.

Show answer

T: Q+=T⊕Q=TQ′+T′QQ^+ = T \oplus Q = TQ' + T'Q. SR: Q+=S+R′QQ^+ = S + R'Q with the condition SR=0SR = 0.

Question 3

A T flip-flop with T=1T = 1 is clocked at 40 MHz. What is the output frequency, and how many such flip-flops in a chain give 2.5 MHz?

Show answer

Each stage halves the frequency: 20 MHz after one stage. 40/2k=2.540 / 2^k = 2.5 gives 2k=162^k = 16, so k=4k = 4 flip-flops.

Question 4

Why is S=R=1S = R = 1 forbidden in the NOR SR latch?

Show answer

Both outputs are forced to 0, so Q=Q′=0Q = Q' = 0, which contradicts Q′=Q' = the complement of QQ. When SS and RR return to 0 at the same time both gates switch together and the final state depends on tiny delay differences, so it cannot be predicted.

Revision card

One-screen revision

  • Latch: level sensitive, transparent. Flip-flop: edge triggered, samples DD at the edge.
  • NOR SR: 00 hold, 01 reset, 10 set, 11 forbidden. NAND SR is active low.
  • Q+Q^+: D = DD; JK = JQ′+K′QJQ' + K'Q; T = T⊕QT \oplus Q; SR = S+R′QS + R'Q.
  • JK: hold, reset, set, toggle. Race-around cured by edge triggering.
  • Master-slave D = two latches. Setup before, hold after the edge. nn flip-flops, 2n2^n states.

References

  • ·Mano and Ciletti, Digital Design, 5th ed., Chapter 5 Synchronous Sequential Logic (sequential circuits, latches, flip-flops)
  • ·Kohavi and Jha, Switching and Finite Automata Theory, Chapter on memory elements and flip-flops

Verification

The latch and flip-flop behaviours in the animations come from discrete-time simulations (scripts/gen-dl-seq-traces.py) that tests/dl-seq-traces.test.ts re-simulates independently. The NOR SR latch, the NAND latch, the four-NAND gated D latch and the six-NAND edge-triggered D flip-flop are simulated gate by gate in scripts/enum-checks/dl_seq.py against the intended behaviour, and the characteristic and excitation tables are enumerated there. The C program is compiled and run by npm run verify:c. Setup, hold and clock-to-Q behaviour is described qualitatively, since those are physical effects not captured by the ideal models. Textbook chapter titles are from memory; the independent second pass has not been run, so the page stays draft. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (conversions, signed ranges and flags, IEEE 754 fields and custom formats, Boolean identities and counts, K-map groups, adder carries, BCD correction, flip-flop conversions, counter sequences and T equations, state reduction, Quine-McCluskey rounds and covers, floating-point alignment and rounding); long C programs were not re-read line by line (they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose); tables and animations are machine output and were read, not re-run; No other defect found. Status raised to self-checked; verified needs a textbook or human check.

last verified: never