Logic gates: AND, OR, NOT, NAND, NOR, XOR and XNOR
A logic gate is a tiny circuit that takes one or more inputs, each 0 or 1, and gives an output that is also 0 or 1. Computers are made of millions of them: every addition, every comparison and every bit of memory comes down to gates.
There are seven basic gates. Each one is described by a truth table: the list of every possible combination of inputs, with the output the gate gives for it. Click the inputs below to try each gate.
AND
Formula Y = A · B Y = A AND B
| A | B | Y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Try it Click the inputs to change them.
OR
Formula Y = A + B Y = A OR B
| A | B | Y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Try it Click the inputs to change them.
NOT
Formula Y = Ā Y = NOT A
| A | Y |
|---|---|
| 0 | 1 |
| 1 | 0 |
Try it Click the inputs to change them.
NAND
Formula Y = (A · B)‾ Y = A NAND B
| A | B | Y |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Try it Click the inputs to change them.
NOR
Formula Y = (A + B)‾ Y = A NOR B
| A | B | Y |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
Try it Click the inputs to change them.
XOR
Formula Y = A ⊕ B Y = A XOR B
| A | B | Y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Try it Click the inputs to change them.
XNOR
Formula Y = (A ⊕ B)‾ Y = A XNOR B
| A | B | Y |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Try it Click the inputs to change them.
Why only 0 and 1?
Inside a chip, a wire is either at a low voltage (0) or a high voltage (1). With only two values, circuits are simple, reliable and cheap to make. The rules for combining 0s and 1s are called Boolean algebra, after the mathematician George Boole.
In what order should I learn them?
Start with NOT, AND and OR: they behave like the everyday words. Then NAND and NOR, which are AND and OR with the output turned upside down, and XOR, which is 1 when its inputs differ. Then the lessons show how gates combine into adders, memory and counters.