Source: https://mokxi.com/learn/flip-flops
Updated: 2026-09-27

Learn

# Flip-flops, clocked by your own hand

Written by the Mokxi team, updated September 27, 2026

Sign up free or see every lesson

- 192 parts on the bench
- 25 boards running now
- 1.00x real time, on every board

Hold the button

One half of a 74HC74: the switch is D, the button is the clock, and the LEDs are Q and Q-bar.

A flip-flop is one bit of memory. The circuit above is one half of a 74HC74 D flip-flop: a slide switch sets D, a pushbutton is the clock, and two LEDs show Q and Q-bar. Set the switch, press the button, and Q copies D. Move the switch without pressing and nothing happens.

We ran that sequence on this circuit: Q started at 0, stayed 0 when D moved to 1, went to 1 on the press, stayed 1 when D went back to 0, and returned to 0 on the next press. That is the whole D flip-flop truth table, and the rest of this page builds on it.

Download the lesson plan (PDF)

## Latch or flip-flop?

A latch responds to the level of its inputs: while it is enabled, its output follows. A flip-flop responds only to an edge of its clock, usually the rising one, and ignores its inputs the rest of the time. Edge triggering is what lets a thousand flip-flops share one clock and all change at the same instant, which is the basis of every synchronous circuit.

## The SR latch

Two NAND gates from a 74HC00, each output fed back into the other gate’s input, make an SR latch with active-low inputs. S-bar = 0 sets Q to 1, R-bar = 0 resets Q to 0, and with both inputs at 1 the latch holds whatever it had. Both at 0 at once forces both outputs high, which is why that row is called invalid.

The circuit uses a slide switch, which connects one input or the other to ground but never both, so it can only set or reset. That is also how a latch debounces a switch: it flips on the first contact and ignores the bounces after it.

## The D flip-flop

D, clock, next Q: 0 on a rising edge gives 0. 1 on a rising edge gives 1. Any D with the clock low, high or falling leaves Q where it was. Q-bar is always the opposite of Q.

The 74HC74 also has an asynchronous set and reset for each flip-flop, active low. Here both are tied to 5 V so they stay out of the way. Pull reset low and Q clears at once, with no clock needed, which is how a counter is zeroed.

## The JK flip-flop

J, K, next Q: 0 0 holds. 1 0 sets. 0 1 resets. 1 1 toggles. The JK flip-flop is a D flip-flop with steering logic in front of it: D = J Q-bar + K-bar Q. Mokxi has no JK chip yet (real ones include the 74HC107), so this circuit builds one from a 74HC74 and four ideal gates, and it behaves the same way.

We checked every row: hold, set, reset, then three presses in toggle mode gave 1, 0, 1. One thing we saw along the way is worth knowing. When a switch and the clock changed at the same instant, the flip-flop took the old value, because the gates had not finished propagating. That is setup time, and real chips specify it in their data sheets.

The clock button here is set not to bounce. Change its bounce property to typical, set J and K to 1, and some presses toggle more than once, because every bounce is another clock edge.

## Divide by two, then count

Tie a D flip-flop’s D to its own Q-bar and every clock edge flips it: Q runs at half the clock frequency. That is a toggle flip-flop, and two of them in a row are a two-bit counter. The counter circuit drives one from a 555 and puts a logic analyzer on the clock and both bits, so you can see each stage change on an edge of the one before it.

## Where flip-flops show up next

Put eight D flip-flops side by side on one clock and you have an 8-bit register: every edge stores a whole byte at once. That is what the registers inside a processor are, and it is why a CPU diagram is mostly flip-flops and adders.

Chain them instead, each Q feeding the next D, and you have a shift register. Every clock edge moves each bit one place along, so a byte can go in one wire at a time and come out eight wires at once. The 74HC595 in the parts bin is exactly that, plus an output latch, and it is how an Arduino drives eight LEDs from three pins.

Feed some outputs back through gates into the D inputs and the flip-flops hold a state that changes by rules on every clock: a state machine. Traffic lights, vending machines and the lock on a keypad all work this way, and the same idea runs in software as a switch statement inside loop(). The Arduino state machine page builds one you can step through.

## Questions

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

On a rising clock edge, Q becomes D. At any other time Q holds its value. Q-bar is always the complement of Q.

Why does my flip-flop change more than once per button press?

The button bounces. A mechanical contact makes and breaks several times in the first few milliseconds, and each of those is a clock edge. Debounce the clock with a latch, an RC filter and a Schmitt trigger, or a 555 one-shot.

What is a T flip-flop?

A flip-flop that toggles on every clock edge when its T input is 1. A JK with J and K tied together is one, and so is a D flip-flop with D tied to Q-bar.

Related

## Keep going

Half Adder and Full Adder: Truth Table to Breadboard Digital Electronics on Chromebooks: Labs by Unit Debouncing a Button: Why It Fires More Than Once Shifting a Byte In, One Edge at a Time Arduino State Machine: A Four-State Reaction Game The 74HC74 part page

## Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.

Start building Open the editor
