Part 8 needed four different chips to test four different gates. This part needs one. A NAND gate is : wire enough of them together and you can build NOT, AND, OR, XOR and any other logic function there is, from a single type of gate. The four NANDs in one 74HC00 are enough to make any one of the basic gates.
The idea is old. The American philosopher Charles Sanders Peirce worked out around 1880 that a single operation, “not both” or “neither … nor”, could express all of logic, but his notes were not published until 1933. In 1913 the American logician Henry Sheffer published a proof that one operation was enough, and NAND is still sometimes called the Sheffer stroke. Both men were working on paper, decades before anyone could build a gate.
The trick rests on two facts from earlier parts. A NAND is an AND with its output turned upside down. And by De Morgan’s laws in part 6, a NAND is also an OR with both inputs turned upside down. Everything else follows.
Join a NAND’s two inputs together and feed them a single signal, A. Both inputs are always equal, so only two rows of the NAND’s truth table are ever used: 0 and 0 gives 1, and 1 and 1 gives 0. The output is the opposite of the input. One NAND with its inputs joined is a NOT.
There is a second way. A·1 = A, so a NAND with one input tied high gives (A·1)′ = A′, also a NOT. Both work; joining the inputs is neater on a breadboard, because it needs one short wire instead of a wire to the + rail.
An AND is a NAND whose output has been turned round again. You now have a NOT made from a NAND, so put one after the other: the first NAND gives (A·B)′, and the second, used as a NOT, turns it back into A·B. Two NANDs make an AND.
Part 5 showed that this is exactly how the 74HC08 does it inside, with a NAND stage followed by a NOT stage. On the breadboard you are building the same thing from the outside.
Here is where De Morgan earns his keep. A NAND is an OR with both inputs inverted:
(A·B)′ = A′ + B′
So feed it inputs that have already been inverted, A′ and B′, and the two inversions cancel: (A′·B′)′ = A + B. Two NANDs, used as NOTs, invert A and B; a third NAND combines them. Three NANDs make an OR.
Add a fourth NAND as a NOT on the output and you have a NOR, in four. And XOR, which looks hardest, also takes only four: one NAND of A and B, whose output then goes to two more NANDs, one with A and one with B, and a last NAND that combines those two.
NAND only
Choose a gate and switch A and B. Follow the signal through the NANDs; every wire is orange when it is 1. The real gate beside it gets the same inputs, and the table checks every row.
OR, A + B = (A′·B′)′
| A | B | NANDs | OR |
|---|---|---|---|
| 0 | 0 | 0 | 0 ✓ |
| 0 | 1 | 1 | 1 ✓ |
| 1 | 0 | 1 | 1 ✓ |
| 1 | 1 | 1 | 1 ✓ |
- Gate 1: pins 1 and 2 joined, fed from A; output on pin 3.
- Gate 2: pins 4 and 5 joined, fed from B; output on pin 6.
- Gate 3: pin 3 → pin 9, pin 6 → pin 10; output on pin 8.
1 NAND left over: tie its inputs to ground.
Pin numbers are for one 74HC00: gate 1 is pins 1, 2 → 3; gate 2 is 4, 5 → 6; gate 3 is 9, 10 → 8; gate 4 is 12, 13 → 11.
NOT, AND and OR are enough to build any truth table you can write down. Part 6 showed how: write the rows that give 1 as a sum of products, an OR of ANDs. Now the last step. By De Morgan, an OR of ANDs is exactly a NAND of NANDs: replace every AND and the final OR with a NAND, and the circuit still computes the same thing. Any truth table can therefore be built from NAND gates alone, in two layers.
NOR is universal too, for the mirror-image reasons: a NOR with its inputs joined is a NOT, and an AND is a NOR of inverted inputs. Between them, NAND and NOR are the only two-input gates that can build everything on their own.
Building an AND from two NANDs looks wasteful when the 74HC08 exists. But a universal gate has three advantages that grow with the size of the project:
- One part to stock. A box of 74HC00s builds anything. On a breadboard, a spare NAND on a chip that is already there often saves adding a whole chip for one gate.
- One part to perfect. Chip designers can make one gate as small, fast and reliable as possible and repeat it. Part 5 showed that in CMOS a NAND is the cheapest gate to make anyway, four transistors to an AND’s six.
- One part to trust. Every gate behaves the same way, with the same timing and the same quirks.
The most famous example flew to the Moon. The Apollo Guidance Computer, which steered the command module and the lunar module, was built almost entirely from one kind of chip: in its final version, about 2,800 chips, nearly all holding two three-input NOR gates. Using one simple chip throughout avoided many of the problems that had dogged another early computer built from mixed types. On 20 July 1969, NOR gates helped land the first people on the Moon.
- The 74HC00 goes in with pin 1 in f14, powered and decoupled as always (a14 to +, j20 to −, 100 nF beside pin 14).
- Buttons and pull-downs as on the test rig: A across columns 3 and 5, B across 8 and 10.
- Gate 1 is the NOT for A: a yellow wire from h5 to h14 (pin 1), and a short wire from g14 to g15 joining pins 1 and 2.
- Gate 2 is the NOT for B: a green wire from i10 to i17 (pin 4), and a short wire from g17 to g18 joining pins 4 and 5.
- Gate 3 combines them: a blue wire from h16 (pin 3) over the chip to c19 (pin 9), and a white wire from i19 (pin 6) to b18 (pin 10).
- The output, pin 8, is in the top row: a wire from b20 to b23, the 330 Ω from c23 to c26, the LED from d26 (long leg) to d27, and a black wire from a27 to the top − rail.
- Tie pins 12 and 13 (a16, a15) to the top − rail.
The LED lights when A, or B, or both are held, and is dark only when neither is: the OR table from part 4, from a chip that has no OR gates in it. Measure pins 3 and 6 as you press: each is the opposite of its button.
Every circuit so far has an output that depends only on its inputs right now: let go of the buttons and it forgets. The next part feeds two NAND gates back into each other, and the result remembers.
Sources for this part
Universal gates
- NAND logic – Wikipedia
- Functional completeness – Wikipedia
- Sheffer stroke – Wikipedia
- Logic gate – Wikipedia
The Apollo Guidance Computer