Universal gates: NOT, AND, OR and NOR from NAND only
NAND is a universal gate: NOT, AND, OR and every other logic function can be built from NAND gates alone. NOT A = NAND(A, A), A AND B = NOT NAND(A, B), and A OR B = NAND(NOT A, NOT B); this circuit builds all of them, plus NOR, from six NANDs.
A set of gates is universal (functionally complete) when any Boolean function can be built from it. AND, OR and NOT together are universal, so if NAND can make those three, NAND alone is universal. It can: tie a NAND's inputs together and it inverts; put that inverter after a NAND and you get AND; and by De Morgan's law, NANDing the two inverted inputs gives OR. NOR is just OR inverted once more. The live circuit shows every output at once, so toggling A and B fills in all four truth tables together.
Open this circuit in the lab →
What you need
- 1× NAND: NOT A: both inputs tied to A
- 2× NAND: A AND B: NAND(A, B), then a NAND used as an inverter
- 2× NAND: A OR B: NOT B from a second inverter, then NAND(NOT A, NOT B) (reusing NOT A)
- 1× NAND: A NOR B: the OR output inverted
Step by step
- Place inputs
AandB. - NOT: wire A to both inputs of a
NAND. NAND(A, A) = NOT (A AND A) = NOT A. - AND: NAND A with B, then invert the result with another tied-input NAND. Two inversions cancel and leave A AND B.
- OR: make NOT B the same way, then NAND the two inverted inputs. By De Morgan, NAND(NOT A, NOT B) = A OR B.
- NOR: invert the OR output with one more tied-input NAND. Probe
NOT,AND,ORandNORand step through the four input rows.
Truth table of every output
| A | B | NOT A | A AND B | A OR B | A NOR B |
|---|---|---|---|---|---|
| 0 | 0 | 1 | 0 | 0 | 1 |
| 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 0 | 0 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 | 1 | 0 |
Gate counts with NAND only: NOT 1, AND 2, OR 3, NOR 4, XOR 4 (see XOR from NAND), and a whole half adder 5. In CMOS a NAND is just four transistors, which is one reason real chips are built so heavily from NAND. In digiwleea you go one level lower still: the NAND itself is built from transistors in the course.
You can also read the full theory in the lesson on NAND, the universal gate. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.
Build more parts from gates
Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab, with the free theory reference alongside.
Open the NOT, AND, OR and NOR from NAND in the lab →Frequently asked
Why is NAND called a universal gate?
Because NOT, AND and OR can all be built from NAND gates alone, and those three can express any Boolean function. So any digital circuit, including a whole CPU, can be built from NAND gates only.
How do you make an OR gate using NAND gates?
Invert each input with a NAND whose inputs are tied together, then NAND the two inverted signals: NAND(NOT A, NOT B) = A OR B by De Morgan's law. That takes three NAND gates.
How do you make an AND gate using NAND gates?
NAND the inputs, then invert the result with a second NAND whose inputs are tied together. NOT (NAND(A, B)) = A AND B. That takes two NAND gates.
How do you make a NOT gate from a NAND gate?
Connect both NAND inputs to the same signal A. NAND(A, A) = NOT (A AND A) = NOT A. (Tying the other input to 1 also works.)
Which gates are universal gates?
NAND and NOR. Each one alone can build NOT, AND and OR, and therefore any logic function. AND, OR or XOR alone cannot.