Can you build every rule there is from just one kind of gate?
Lesson 4.2 · Flip It
Jenny · Sarah · Rob
A switch that works backwards. On purpose.
Jenny adds a third trick: a switch wired so the bulb is on when the switch is off, and off when it’s on.
Backwards. Sarah thinks it’s broken.
Jenny says it’s about to become the most important gate there is, once you stick it on the end of an AND.
The short answer
Yes. NAND can make NOT, AND, OR and XOR, and from those you can build anything a computer does. Jenny’s backwards switch, stuck on the end of an AND, is enough to build a processor. It just takes a billion of them.
Try it yourself
Try every combination on these three gates.
One switch, flipped. What does the light do?
NOT
Flips the one switch: on becomes off, off becomes on.
What you just did has a name
NOT, NAND and XOR
A NOT gate flips its one input: on becomes off.
NAND means “not AND”: it’s off only when both inputs are on. XOR, “exclusive or,” is on when exactly one input is on.
Here’s the surprise: every other gate, and so every circuit in every computer, can be built from NAND gates alone.
One gate, copied billions of times, is enough.
A few more things
Why NAND is enough
Wire a NAND’s two inputs together and you get NOT. Put a NOT after a NAND and you get AND. With NOT and AND you can build OR. From there, anything.
XOR is the adding gate
XOR shows up when computers add. In binary, 1 plus 1 is 0 with a 1 carried, and XOR gives you that 0. Module 5 builds an adder out of it.
Real chips mix them
Chip designers use whatever gates are fastest and smallest for each job. But they could, in principle, do it all with NAND.
Go deeper
The longer version, if you want it.
Build a computer from one part
There’s a well-known course where students start with nothing but a NAND gate and build, step by step, every other gate, then an adder, then memory, then a whole processor, then an operating system and a game. It works because NAND really is enough.
The point isn’t that real chips are built that way. It’s that a computer is not a mystery box. It’s one very simple idea, stacked very high.
Quick check
A NOT gate’s input is on. What’s its output?
Let’s take it slower
NOT is the word “not” in a sentence: “the door is NOT locked” is true exactly when “the door is locked” is false. NAND is “NOT (both)”: it’s true unless both things are true. XOR is the “one or the other, not both” you mean when a waiter says “soup or salad.”
More examples
Only one can hold the ball
Keep-away only works if exactly one of you has the ball. You have it or your friend does. If you both grab it, the game falls apart. Exactly one is XOR.
The seatbelt light
It’s on when someone is sitting in the seat AND the belt is NOT buckled. One AND, one NOT, and a chime.
Back to the question
So can one kind of gate build everything?
Show the answer
Yes. NAND can make NOT, AND, OR and XOR, and from those you can build anything a computer does. Jenny’s backwards switch, stuck on the end of an AND, is enough to build a processor. It just takes a billion of them.
One last question
Which of these would you trust?
“A NOT gate turns on into off and off into on.”
“XOR is on when both inputs are on.”
“Every circuit in a computer could be built from NAND gates alone.”
“NAND is on only when both inputs are on.”
Talk Card
Talk Card · 4.2
You could build an entire computer out of one kind of gate. NAND is enough, copied billions of times.
How Computers Work · pettigrewlab.com/learn


