Lessons in IT Basics

Hardware Basics · Lesson 3 · 7 min read

The NAND Gate

By the end of this lesson

  • Discover the rule a NAND gate follows by reasoning through a thought experiment
  • Read a truth table and predict the output for any input combination
  • Explain why NAND is the single building block all of computing is built from

In the last lesson I showed you that everything in a computer is built from bits — single yes/no answers. Now I want to show you what a computer actually does with those bits. And to make it concrete, I’m going to start somewhere very physical: a strange room with two light switches.

The most fundamental part of every computer ever built is hiding in plain sight. I could just tell you what it is and how it works — but it sticks better if you discover it for yourself.

Let me tell you a small story. Imagine this:

It’s a bright sunny day. The windows are open, light is pouring in, and yet the ceiling lamp is on. That seems like a waste of electricity. You decide to turn it off.

There are two switches on the wall by the door. Both are pointing down, which usually means off — and yet the light is on. Strange. You figure one of them must have been installed upside down. You flip the first switch up. Nothing happens. You flip it back down and try the second one. Nothing. You put the second one back. Still on.

You start flipping switches at random, getting more annoyed by the second. Then, mid-frustration, the light blinks off for a fraction of a second. You stop. You back up. You try things slowly, one switch at a time.

After a minute of careful experimenting, the rule clicks into place. The light goes off only when both switches are up. The moment either one drops back down, the light comes on again. One switch off, the other off, both off — light is on. Both on — light is off.

Goofy. But you got what you wanted. You leave the room shaking your head.

Switch A

Switch B

Light is on

Try to turn off the light. There's a rule hidden in this room — find it.

Now write down the rule

Click each cell to toggle between “off” and “on”.

Switch ASwitch BLight
offoff
offon
onoff
onon

The pattern

That strange room is wired exactly like the most fundamental part of every computer. The two switches are inputs. The ceiling light is the output. The rule the room follows — both inputs on means the output is off, anything else means the output is on — is the rule a NAND gate follows.

Switch ASwitch BLight
offoffon
offonon
onoffon
ononoff

In one sentence: the output is off only when both inputs are on. Otherwise, the output is on.

Now in the language of computers

From now on I’ll switch my notation. Instead of writing “on” and “off”, I’ll write “1” and “0” — the way computer engineers do. They mean exactly the same thing. A switch that’s on is a 1. A switch that’s off is a 0. The light being on is a 1, and the light being off is a 0. That’s it — same idea, shorter to write.

The symbol

Computer engineers don’t draw the full schematic of a NAND gate every time they need one — they’d never finish a single chip. Instead, they use a small standardized symbol that everyone in the field instantly recognizes.

The NAND gate symbol

The NAND gate symbol.

This is the first of several gate symbols you’ll meet. Each kind of gate has its own — a NOT gate gets a triangle, an AND gate gets a D-shape without the bubble (the bubble is what makes it “NOT-AND”), an OR gate gets a curved shield. Don’t try to memorize them yet — you’ll meet each one as you build it. The point right now is just to know that this funny D-shape with a circle on the end means “NAND” to anyone who reads circuit diagrams.

Here’s the NAND gate again — same logic as the room, drawn the way real engineers would draw it, and using 1/0 instead of on/off:

Try it — toggle the inputs
1
NAND(0, 0) = 1

Try every combination. You should see exactly the pattern from the room: three combinations produce a 1, and only one — both inputs on — produces a 0. The “N” in NAND stands for “not”: it’s a NOT-AND, the opposite of an AND gate.

Why this gate, of all gates?

There are other gates with their own names — AND, OR, NOT, XOR — and you’ll meet them all soon. But the NAND gate has a remarkable property: every other gate, and in fact every part of a computer, can be built by wiring NAND gates together. Memory bits, adders, registers, the whole CPU — all of it is just NAND gates.

This isn’t an exaggeration or a thought experiment. Real chips are built this way. The NAND gate is the LEGO brick of computing.

In the next lesson, you’ll wire a NAND gate to itself and discover that this single move is enough to build a NOT gate — a gate that flips its input. From there, every other gate falls out one by one.