How to build an OR gate from NAND gates
An OR gate takes three NAND gates. Invert A and B with two NAND gates wired as NOT gates, then feed both into a third NAND. The output is 1 whenever A or B (or both) is 1.
- 3NAND gates
- Yesfewest possible
- 2inputs
- 1output
The formula
Q = NAND(NOT A, NOT B) = NAND(NAND(A, A), NAND(B, B))
How it works
This one rests on De Morgan's law: A OR B is the same as NOT (NOT A AND NOT B). In words: "at least one is on" means "it is not the case that both are off".
NOT (something AND something) is exactly what a NAND computes. So invert each input, NAND them, and you have OR.
The last gate outputs 0 only when both of its inputs are 1, which happens only when A and B are both 0. Every other case gives 1.
Gate by gate
- A NOT gate on A. Outputs 1 when A is 0.
- A NOT gate on B. Outputs 1 when B is 0.
- NANDs the two inverted inputs. Outputs 0 only when A and B are both 0, so the result is A OR B.
Truth table
| A | B | Q |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Why 3 NAND gates?
Three is the fewest possible. An exhaustive search over every one- and two-gate circuit finds none that make OR.
Where it's used
OR combines conditions: "carry out if either half adder carried" in a full adder, or "interrupt if any device asks".