XOR, NAND, and NOR
Logic Gates · Foundations track
3 min read
In this module
Beyond the Basics
Now that you know AND, OR, and NOT, you're ready for three more gates. Each one is built by combining the fundamentals, but they show up so often in circuit design that they've earned their own names and symbols.
The XOR Gate
XOR stands for exclusive OR. It outputs 1 when the inputs are different and 0 when they are the same.
| A | B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
The big difference from OR: when both inputs are 1, OR outputs 1 and XOR outputs 0. XOR is essentially asking, "Is exactly one of these true?" That single question turns out to be wildly useful for binary addition and error detection.
The NAND Gate
NAND means NOT AND. Take the output of an AND gate and invert it.
| A | B | A NAND B |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
A NAND gate outputs 0 in exactly one case, when both inputs are 1. The mirror image of AND.
The NOR Gate
NOR means NOT OR. Take the output of an OR gate and invert it.
| A | B | A NOR B |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
A NOR gate outputs 1 only when both inputs are 0.
NAND and NOR are called universal gates because you can build any other logic gate using only NAND gates or only NOR gates. That has practical weight too. In CMOS, the transistor technology inside almost every modern chip, NAND and NOR are among the cheapest gates to build: an AND gate is really a NAND with an inverter bolted on. The Apollo Guidance Computer took the idea to its limit and was built from NOR gates alone.
Why Universal Gates Matter
Imagine a factory that can only produce one type of gate. If that gate is NAND, you can still build AND, OR, NOT, XOR, and every other gate by wiring multiple NANDs together. Connect both inputs of a NAND to the same signal and you've got a NOT gate. Chain two NANDs and you get an AND. That universality is one of the most elegant ideas in digital design.
Here are AND and OR built from nothing but NANDs. In each diagram, a NAND with both inputs tied to the same wire is acting as a NOT.
The AND version is easy to believe: NAND is AND followed by NOT, so a second NOT cancels the first. The OR version is less obvious, so check it row by row:
| A | B | NOT A | NOT B | (NOT A) NAND (NOT B) |
|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 | 1 |
The last column matches the OR truth table exactly. The next lesson gives you the rule behind it, De Morgan's theorem, so you won't need a table every time.
Next we step back from individual gates and pick up the mathematical language that describes how they combine: Boolean algebra.