Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksBuild a CPUToolsOpen the lab →

2-bit up/down counter: synchronous circuit, live

A 2-bit up/down counter counts 0, 1, 2, 3 when UP = 1 and 3, 2, 1, 0 when UP = 0, with both flip-flops on one clock. Bit 0 toggles on every clock, and bit 1 toggles when Q0 = 1 counting up or Q0 = 0 counting down: D0 = NOT Q0, D1 = Q1 XOR (Q0 XNOR UP).

Counting up, a bit flips when all lower bits are 1; counting down, when they are all 0. With only one lower bit, that condition is Q0 when UP = 1 and NOT Q0 when UP = 0, which is exactly Q0 XNOR UP. A D flip-flop that should toggle gets its own output XORed with the toggle condition, so D1 = Q1 XOR (Q0 XNOR UP). As T or JK flip-flops the design reads T0 = 1 and T1 = Q0 UP + Q0' UP'. Because both flip-flops share the clock, the direction can change at any time and the next clock simply counts the other way. Each D is ANDed with NOT CLR, a synchronous clear to 00. The same idea scales bit by bit to the 4-bit up/down counter; the up-only version is the mod-4 counter, and the ripple up/down counter does it without a shared clock.

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 →

Embed or cite this circuit

Free to embed on a course page, blog or worksheet: paste this code. The circuit stays live, and the small digiwleea badge links back here.

To cite it: digiwleea, “2-bit up/down counter”, https://digiwleea.wleeaf.dev/tools/build/up-down-counter-2bit/

What you need

Step by step

  1. Place two D flip-flops on one clock, inputs UP and CLR, and probes Q1 and Q0.
  2. D0 = NOT Q0, so bit 0 toggles on every clock.
  3. XNOR Q0 with UP, then XOR that with Q1 for D1.
  4. AND both D inputs with NOT CLR, clear once, then clock with UP = 1: 00, 01, 10, 11, 00.
  5. Set UP = 0 and keep clocking: the count runs 11, 10, 01, 00, 11.

2-bit up/down counter state table

UPQ1 Q0 nowQ0 XNOR UPQ1 Q0 next
100001
101110
110011
111100
000111
011010
010101
001000

Before the page is built, the live circuit runs 16 clocks: up for six, down for six and up again, with both outputs checked after every clock.

You can also read the full theory in the lesson on synchronous counters. 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.

More builds: Registers and counters

All 246 build guides, by topic

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 2-bit up/down counter in the lab →

Frequently asked

How do you design a 2-bit up/down counter?

Bit 0 toggles every clock (D0 = Q0'). Bit 1 toggles when Q0 = 1 counting up and when Q0 = 0 counting down, so its toggle condition is Q0 XNOR UP and D1 = Q1 XOR (Q0 XNOR UP).

How many flip-flops does a 2-bit up/down counter need?

Two, one per bit. The direction input changes only the logic in front of the second flip-flop.

What are the T flip-flop inputs of a 2-bit up/down counter?

T0 = 1 and T1 = Q0 UP + Q0' UP', which is Q0 XNOR UP.