Computing Library › Classical Logic Gates
Classical Logic Gates
NAND Gate
The NAND gate outputs 0 only when all inputs are 1; it is an AND followed by inversion and is functionally complete.
What it does
NAND stands for NOT-AND. Its output is the complement of AND: it is 0 only when every input is 1, and 1 in all other cases. The symbol is an AND shape with an output bubble.
Truth table
| A | B | A NAND B |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Why it is special
NAND is a universal gate: any Boolean function can be built from NAND alone. Because CMOS pull-down networks invert naturally, NAND is also one of the cheapest and fastest gates to fabricate, which is why it is a preferred primitive.
Building other gates from NAND
- NOT: tie both inputs together, giving NAND(A, A) = NOT A.
- AND: follow a NAND with a NAND-based inverter.
- OR: invert both inputs first, then NAND them, per De Morgan's laws.
- Any function: express it in AND/OR/NOT form and translate each piece.
Algebraic form
A NAND B equals NOT(A AND B). By De Morgan's laws this also equals NOT A OR NOT B, a useful identity when rearranging logic.
In code
python
out = 1 - (a & b) # NAND of two 0/1 bits
out = not (a and b) # logical NAND
Its completeness and manufacturing efficiency make NAND a cornerstone of digital design.