Why one gate is enough
NAND means NOT AND. It gives 0 only when both inputs are 1, and 1 for every other row. Watch the lamps: A and B are the inputs, Y is the output, and the table highlights each row.
A set of gates is functionally complete when it can build any truth table at all. NOT, AND and OR together can do that. So if NAND alone can make those three, a chip full of NANDs can build any circuit.
Building from NAND
Wire A to both inputs of one NAND. Now the inputs are always the same: 0 and 0 gives 1, and 1 and 1 gives 0. The output is always the opposite of A, so this NAND works as a NOT gate.
AND is NAND with its answer flipped back. So feed A and B into one NAND, then send its output into a second NAND with joined inputs, which is a NOT. Y is 1 only when A and B are both 1.
For OR, first flip each input with its own joined NAND, giving NOT A and NOT B. A third NAND takes those. It outputs 0 only if both flipped inputs are 1, meaning A and B were both 0. That is OR.
This is De Morgan's law: NOT (A AND B) equals NOT A OR NOT B. Feed in NOT A and NOT B and the NOTs cancel, so the NAND gives A OR B. The table shows the middle values too.
NOR, and inside the chip
NOR (NOT OR) is also functionally complete. Join its inputs and it is a NOT. Swap the three NANDs of the OR circuit for NORs, and the same wiring now gives AND: Y is 1 only when A and B are both 1.
Inside a chip, a NAND is four CMOS transistors. Two pMOS, which switch on when their input is 0, sit side by side from power to Y. Two nMOS, which switch on at 1, sit in a row from Y to ground.
A NAND needs only four transistors; an AND needs six, because it is a NAND plus a NOT. A NOR also needs four, but its two in a row are pMOS, which are slower. So designers often build with NAND.
The circuit, row by row
;; step 1/9 · nand-recap ;; about: Input A, Input B, Last gate, Output Y, Table card A B → Y 0 0 → 1 0 1 → 1 1 0 → 1 1 1 → 0 Python: def nand(a, b): return 1 - (a & b)
Inside a chip, 1 and 0 are two voltage levels (high and low); the lamps just show them. On the gate bench, a coloured wire with moving dashes carries a 1 and a white wire carries a 0. On the transistor board, colour and dashes mark the path the switched-on transistors open: from power to Y (Y is 1) or from Y to ground (Y is 0). In Python, a & b on the numbers 0 and 1 is AND, and 1 - x flips a bit (~x would give -(x + 1)).