Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksToolsOpen the lab →

CD4017 decade counter: how the Johnson counter works, live

The CD4017 is a decade counter with ten decoded outputs: each rising edge on CLOCK moves a single high output one step along, from O0 to O9 and back to O0, so exactly one of the ten outputs is high at a time. Inside it is a 5-stage Johnson counter and ten 2-input AND gates. This live circuit is built the same way.

TI's datasheet (from Harris Semiconductor) explains the design choice: "Use of the Johnson counter configuration permits high-speed operation, 2-input decode-gating and spike-free decoded outputs." A Johnson counter of five flip-flops steps through ten states in which exactly one bit changes per clock, so each count is identified by just two neighbouring bits, for example O1 = Q0 AND NOT Q1, and no decoder output can glitch. CARRY OUT is high for counts 0 to 4 and low for 5 to 9, one cycle every ten clocks, which is how one CD4017 clocks the next in a multi-digit chain. RESET high returns the count to 0, and CLOCK INHIBIT high stops the clock (the datasheet adds that with CLOCK held high, the inhibit input can serve as a falling-edge clock). The real chip also has anti-lock gating that steers it back to a valid state; this version omits it and starts from RESET instead. Here CLOCK is a plain switch, so you count by hand. It opens with RESET high: set RESET to 0, then turn CLOCK on and off to step O0 to O9. Before the page is built, a 33-step sequence (reset, a full lap of ten clocks, two blocked clocks under CLOCK INHIBIT, two more clocks, reset) is checked on all eleven outputs.

Big circuit: pinch, scroll or tap + to zoom in, then drag to move around.

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 →

What you need

Step by step

  1. Place inputs CLOCK, INHIBIT (CLOCK INHIBIT) and RESET, and probes O0 to O9 and CARRY.
  2. Build a 5-stage Johnson counter: five D flip-flops with clear, D0 = NOT Q4 and each later stage fed from the one before, all cleared by RESET and clocked by CLOCK AND NOT INHIBIT.
  3. Decode each count with one 2-input AND: O0 = Q0' Q4', O1 = Q0 Q1', O2 = Q1 Q2', ..., O5 = Q4 Q0, O6 = Q0' Q1, ..., O9 = Q3' Q4.
  4. Add CARRY = NOT Q4, high for counts 0 to 4.
  5. Set RESET to 0 and pulse CLOCK: the high output walks from O0 to O9, then wraps to O0.

The ten counts

CountQ0 Q1 Q2 Q3 Q4High outputDecoded byCARRY
00 0 0 0 0O0Q0' Q4'1
11 0 0 0 0O1Q0 Q1'1
21 1 0 0 0O2Q1 Q2'1
31 1 1 0 0O3Q2 Q3'1
41 1 1 1 0O4Q3 Q4'1
51 1 1 1 1O5Q4 Q00
60 1 1 1 1O6Q0' Q10
70 0 1 1 1O7Q1' Q20
80 0 0 1 1O8Q2' Q30
90 0 0 0 1O9Q3' Q40

CD4017 pinout

PinNamePinName
1O516VDD
2O115RESET
3O014CLOCK
4O213CLOCK INHIBIT
5O612CARRY OUT
6O711O9
7O310O4
8VSS9O8

The outputs are scattered around the package, so check the pinout before wiring LEDs in order. Pinout and behaviour are from TI's CD4017B datasheet (SCHS027C), checked 2026-10-25; it runs from 3 V to 18 V. Each decoded output stays high for one full clock cycle. The datasheet lists decade counting with a decimal display, frequency division and divide-by-N counting among its uses.

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

half adderfull adderhalf subtractorfull subtractor2:1 multiplexer4:1 multiplexerXOR gate from NAND gates2-to-4 decoderSR latchD flip-flopJK flip-flopT flip-flop4-bit shift register4-bit ripple carry adderD latch1-to-4 demultiplexer4-bit magnitude comparator4-bit ring counter4-bit Johnson counter4-to-2 priority encoder4-bit synchronous counter3-to-8 decoder8-to-1 multiplexer4-bit carry lookahead adderhalf adder from NAND gates2-bit comparatorBCD to 7-segment decoder4-bit up/down counterdecade counter2-bit multiplier4-bit ALU4-bit array multiplierNOT, AND, OR and NOR from NANDNOT, OR, AND and XOR from NORfull adder from NAND gatesSR latch from NAND gatesparity generator and checker4-bit adder/subtractorBCD adder4-bit universal shift registermod-6 counter4-bit ripple counterbinary to Gray code converterhalf adder from NOR gatesfull adder from NOR gates4-bit register with parallel load1011 sequence detectorbinary to BCD converterD flip-flop from NAND gates1-bit ALUCMOS inverterCMOS NAND gateCMOS NOR gatePISO shift registerSR flip-flop from NAND gatesBCD to excess-3 code converterHamming (7,4) code encoder and correctortraffic light controller4-bit barrel shifterCMOS AND gateCMOS OR gateCMOS XOR gate1-bit magnitude comparatorhalf subtractor from NAND gatesfull subtractor from NAND gates8-to-3 encoderGray to binary converter4-to-16 decoderfull adder using 4:1 multiplexersedge detectorserial adder4-bit carry-select adder4-bit Kogge-Stone adder4-bit carry-skip adder4x4 Wallace tree multiplier8-bit adderfrequency divider (by 2, 4 and 3)switch debouncer (SR latch)3-bit Gray code counterMealy machine (1011 detector)master-slave JK flip-flop (NAND)half subtractor from NOR gates1-to-8 demultiplexerexcess-3 to BCD code convertervending machine FSM4-bit carry-save adder3-bit synchronous counter (JK)CMOS transmission gatetri-state buffer (CMOS)2-to-1 mux from transmission gatesmod-5 counterflip-flop conversion (JK to D)8-bit ALUdecimal to BCD encoderBCD to decimal decoder4-to-1 mux from 2-to-1 muxesXOR gate from NOR gates4-bit LFSR74LS138 decoderBCD subtractor74181 ALUCMOS AOI gate (AOI21)D latch vs D flip-flop74LS47 BCD to 7-segment decoder74HC595 shift register7400 quad NAND gate chip7402 quad NOR gate chip7404 hex inverter chip7408 quad AND gate chip7432 quad OR gate chip7486 quad XOR gate chip7474 dual D flip-flop74HC165 shift register74LS283 4-bit adder74LS90 decade counter74HC161 4-bit counter

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 CD4017 decade counter in the lab →

Frequently asked

How does the CD4017 work?

It is a 5-stage Johnson counter with ten decoded outputs. Each rising clock edge (with CLOCK INHIBIT low) advances the count, and the output for the current count is high while the other nine are low, so a single high output steps from O0 to O9 and wraps around.

What does the RESET pin on a CD4017 do?

A high level on RESET clears the counter to its zero count, so O0 goes high. A common trick is to wire an output, such as O5, back to RESET so the chip counts 0 to 4 and repeats, a divide-by-5 counter.

What is CARRY OUT on the CD4017?

An output that is high for counts 0 to 4 and low for 5 to 9, so it completes one cycle every ten clock pulses. Feeding it to the CLOCK input of a second CD4017 makes the second chip count the tens.

Why does the CD4017 use a Johnson counter?

In a Johnson counter only one flip-flop changes per clock, and each of its ten states can be recognized from just two neighbouring bits. That gives 2-input decoding and decoded outputs without glitches, as the datasheet says, and it allows high-speed operation.

What is the CD4017 pinout?

Pin 1 O5, 2 O1, 3 O0, 4 O2, 5 O6, 6 O7, 7 O3, 8 VSS, 9 O8, 10 O4, 11 O9, 12 CARRY OUT, 13 CLOCK INHIBIT, 14 CLOCK, 15 RESET, 16 VDD.