Sub topic 18
Building Any Gate from NAND or NOR
This chapter assumes you know the truth tables for NOT, AND, OR, NAND and NOR from the previous chapter. It also assumes you know the transistor works as a switch.
Why NAND and NOR are universal
A gate is universal if you can build every other gate from copies of it alone. NAND and NOR both have this property. In practice, a chip maker can then produce one gate type in large numbers. This is why NAND and NOR matter in JEE questions: they ask you to build a gate from them.
The key facts come from two rules:
- Joining both inputs of a NAND gate together gives NOT, because NAND(A, A) = NOT(A·A) = NOT A.
- De Morgan's law says NOT(A + B) = NOT A · NOT B, and NOT(A · B) = NOT A + NOT B.
Building from NAND
| Target gate | Construction using NAND | NAND gates used |
|---|---|---|
| NOT | Tie both inputs together: NAND(A, A) | 1 |
| AND | NAND(A, B), then NOT it | 2 |
| OR | NOT A and NOT B, then NAND them | 3 |
Check OR with De Morgan: NAND(NOT A, NOT B) = NOT(NOT A · NOT B) = A + B.
Building from NOR
NOR works the same way with the roles of AND and OR swapped.
| Target gate | Construction using NOR | NOR gates used |
|---|---|---|
| NOT | Tie both inputs together: NOR(A, A) | 1 |
| OR | NOR(A, B), then NOT it | 2 |
| AND | NOT A and NOT B, then NOR them | 3 |
Check AND: NOR(NOT A, NOT B) = NOT(NOT A + NOT B) = A · B.
Verifying in code
This program builds NOT, AND and OR from NAND only, then checks that they match the real operations.
def nand(a, b):
return 1 - (a & b)
def not_(a):
return nand(a, a)
def and_(a, b):
return not_(nand(a, b))
def or_(a, b):
return nand(not_(a), not_(b))
print("A B | AND OR")
for a in (0, 1):
for b in (0, 1):
assert and_(a, b) == (a & b)
assert or_(a, b) == (a | b)
print(a, b, "|", and_(a, b), " ", or_(a, b))The assertions pass, so the NAND-only circuits reproduce the AND and OR truth tables.
Common errors
- Counting gates wrongly. The standard answers are 1, 2 and 3 for NOT, AND and OR from NAND. For NOR they are 1, 2 and 3 for NOT, OR and AND.
- Forgetting the final inversion. NAND alone gives NOT(A·B), not AND.
- Mixing up the two families. NAND needs an extra inversion to give AND. NOR needs an extra inversion to give OR.
Exercise
How many NOR gates are needed to build a two-input AND gate, and what is the circuit?
Show answer
Three. Use two NOR gates with tied inputs to get NOT A and NOT B. Feed these into a third NOR gate. The output is NOT(NOT A + NOT B) = A·B by De Morgan's law.
Exercise
Show that a NAND gate with inputs A and B followed by a NAND gate with both inputs tied gives the AND function.
Show answer
The first gate gives NOT(A·B). The second gate has both inputs equal to NOT(A·B), so it gives NOT(NOT(A·B)) = A·B. This is AND, built from two NAND gates.