Logic Gates — worked example

Digital Logic 101 · Logic Gates · Example

Build a 3-input AND from NAND gates

ABCY
Figure 1. 3-input AND from four 2-input NANDs. Stage 1 combines A and B into a NAND; stage 2 inverts that NAND back to AND; stage 3 ANDs the result with C via the same NAND-then-invert trick.
  1. Stage 1 — NAND of A and B. Compute P=A⋅B‾P = \overline{A \cdot B} with one 2-input NAND.
  2. Stage 2 — invert P to recover AND. Tie both inputs of a second NAND to PP; the gate behaves as a NOT, so its output is Q=P‾=A⋅BQ = \overline{P} = A \cdot B.
  3. Stage 3 — NAND of Q and C. R=Q⋅C‾=A⋅B⋅C‾R = \overline{Q \cdot C} = \overline{A \cdot B \cdot C}.
  4. Stage 4 — invert R. A fourth NAND with both inputs tied to RR outputs Y=R‾=A⋅B⋅CY = \overline{R} = A \cdot B \cdot C. Done — four NANDs, no other gate types.

Verify with the 8-row truth table

ABCA·B·CY
00000
00100
01000
01100
10000
10100
11000
11111
Figure 2. Y agrees with A · B · C in every row, so the four-NAND network correctly implements 3-input AND.
The pattern NAND-then-NAND-as-NOT appears every time you want an AND from NANDs. Cascading nn-input AND from 2-input NANDs takes 2(n−1)2(n - 1) NAND gates total — two per AND-pair.

Try drawing this — and other circuits — in the Logic Gates Visual Lab.

Hands-on

Try it in the Circuit Toolkit

Pick a gate, toggle its inputs and watch the output and truth table respond. For NAND and NOR universality, the Universal Gate Builder builds every gate from just one type.
Open the Logic Gates Visual Lab →