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

CD4013: the CMOS dual D flip-flop chip, live

The CD4013 is a CMOS chip with two independent D flip-flops. Each copies its D input to Q on the rising edge of its CLOCK, and has SET and RESET inputs that are active HIGH and work at once, without the clock: SET = 1 forces Q to 1, RESET = 1 forces it to 0. This live circuit has both flip-flops.

TI's datasheet (CD4013B) puts it plainly: "The logic level present at the D input is transferred to the Q output during the positive-going transition of the clock pulse. Setting or resetting is independent of the clock and is accomplished by a high level on the set or reset line, respectively." That active-high SET and RESET is the main difference from the TTL-family 7474, whose preset and clear are active low, along with a different pinout and a supply range of 3 V to 18 V. The datasheet suggests two common uses: shift registers, and counters or toggles made by connecting the Q' output back to D, which divides a clock by two. Each flip-flop here is the six-NAND edge-triggered design with inverters on SET and RESET, which also reproduces the datasheet's last row: with SET and RESET both high, both Q and Q' are high. CLOCK is a plain switch here. The live chip opens with both RESET inputs high (both Q = 0): set RESET1 to 0, choose D1 and turn CLOCK1 on. Before the page is built, an 11-step sequence (reset, set, both edges with D at 1 and 0, the other flip-flop on its own clock, and SET = RESET = 1) is checked on all four outputs.

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, for each flip-flop n, inputs Dn, CLOCKn, SETn, RESETn and probes Qn and Qnbar.
  2. Build each as an edge-triggered D flip-flop with asynchronous preset and clear.
  3. Drive the preset from NOT SET and the clear from NOT RESET, so both work when HIGH.
  4. Keep SET and RESET low, put a value on D, and raise CLOCK: Q takes it. Raise SET or RESET to force Q at any time.

CD4013 function table (each flip-flop)

CLOCKSETRESETDQQ'
rising00001
rising00110
falling00Xno changeno change
X01X01
X10X10
X11X11

CD4013 pinout

PinNamePinName
1Q114VDD
2Q1'13Q2
3CLOCK112Q2'
4RESET111CLOCK2
5D110RESET2
6SET19D2
7VSS8SET2

X means the input does not matter. The function table, the description and the 14-pin pinout are from TI's CD4013B datasheet (SCHS023E), checked 2026-10-25. Unused CMOS inputs, SET and RESET included, should be tied to VSS or VDD rather than left open.

You can also read the full theory in the lesson on the D flip-flop. 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 registerCD4017 decade counter74LS283 4-bit adder74LS90 decade counter74HC161 4-bit counter74HC151 8-to-1 multiplexer74HC157 quad 2-to-1 multiplexer74HC139 dual 2-to-4 decoderCD4511 BCD to 7-segment decoder7492 divide-by-12 counter7493 4-bit binary counter74HC244 octal bufferRace-around condition (JK latch)74HC373 octal latch74HC374 octal D flip-flopTurnstile state machine1-to-2 demultiplexerhalf adder using 2:1 multiplexersregister file (4 x 4-bit)digital PWM generator74LS76 dual JK flip-flop7410 triple 3-input NAND chip7411 triple 3-input AND chip7420 dual 4-input NAND chipCD4011 quad 2-input NAND chipCD4001 quad 2-input NOR chipCD4081 quad 2-input AND chipCD4069 hex inverter chip74HC164 8-bit shift register7485 4-bit magnitude comparator74HC125 quad tri-state bufferCD4040 12-stage binary counterCD4060 14-stage counter and oscillator74LS193 4-bit up/down counterelectronic dice circuitmemory address register (MAR) and MDRhardware stack with a stack pointerdirect-mapped cache8-bit Brent-Kung adder4x4 Dadda multiplierbinary clock circuit

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 CD4013 dual D flip-flop in the lab →

Frequently asked

What does the CD4013 do?

It contains two independent rising-edge D flip-flops, each with D, CLOCK, SET and RESET inputs and Q and Q' outputs. SET and RESET are active high and override the clock.

What is the difference between the CD4013 and the 7474?

Both are dual D flip-flops with asynchronous set and reset, but the CD4013's SET and RESET are active high while the 7474's preset and clear are active low, the pinouts differ, and the CD4013 is a 4000-series CMOS part that runs from 3 V to 18 V.

How do you make a toggle flip-flop with a CD4013?

Connect Q' back to D and keep SET and RESET low. Each rising clock edge then loads the opposite of Q, so the output toggles and divides the clock frequency by two.

What happens if SET and RESET are both high on a CD4013?

Both Q and Q' go high, as the datasheet's function table shows. It is not a useful storage state; the result when both are released depends on which one goes low last.