NAND
The universal gate
A NAND gate outputs 0 only when both of its inputs are 1, and 1 in every other case. It is called universal because every other logic gate can be built from NAND gates alone.
Build it in the lab →Time to run the recipe from designing gates on a two-input gate. You will read the truth table, place the NMOS pull-down for the
0 rows, and mirror it with the PMOS pull-up. Same CMOS skeleton as the inverter, just two transistors in each network instead of one.NAND stands for NOT-AND: it does an AND and then inverts the result. Its output is
0 only when both inputs are 1, and 1 in every other case.| A | B | F |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
0 sits in the row where both inputs are 1.NAND is universal: wire up enough NANDs and you can reproduce NOT, AND, OR, XOR, and from there any logic at all. That is why chips lean on it, and why this course builds nearly everything else from the NAND you make here.
An analogy for the behavior: picture a machine with two safety interlocks and a warning lamp. The lamp stays on (
1) as long as *anything* is unsafe, and only goes dark (0) when both interlocks are engaged at once. "Off only when both are on" is exactly NAND, and it is why NAND reads as "not (both)."Designing it from the truth table
Recall the rule: an NMOS conducts when its gate is
1, a PMOS when its gate is 0, and the pull-up and pull-down networks are always exact opposites, so exactly one is connected at a time. So read off when the output must be 0 versus 1:- The output is
0only whenAandBare both1. To pull down only in that case, put the two NMOS in series (stacked): current reachesGNDonly when both gates are1. Series = AND. - The output is
1wheneverAorBis0. To pull up in either of those cases, put the two PMOS in parallel: either one conducting (gate0) connects the output toVCC. Parallel = OR. - Wire one input to one PMOS gate and one NMOS gate; wire the other input to the remaining pair. Series-down, parallel-up: that is a NAND.
F = ¬(A ∧ B)
A and B each drive one of each. Open it in the lab and confirm only A=B=1 pulls the output low.Notice the pattern you can reuse for any gate: series transistors = AND-like (all must conduct), parallel transistors = OR-like (any can conduct). NOR is this same circuit with the two networks swapped. Hold onto that and you can derive every gate in this course by hand.
Try it
Build NAND in the lab and sweep all four input rows. Then think structurally: which is in series, the two NMOS or the two PMOS? Why does that give a
0 only when both inputs are 1?Answer
The two NMOS are in series (stacked). Current reaches
GND only when *both* NMOS conduct, which needs both gates at 1, so the output is pulled low only in the A = B = 1 row. The two PMOS are in parallel, so any input being 0 pulls the output high. Series down, parallel up: that is NAND.Building any circuit from NAND alone
Earlier we called NAND universal. Here is the mechanical way to make good on that promise, and why chip designers bother. In CMOS a NAND is four transistors. A plain AND is a NAND with a NOT bolted on its output, so six transistors, and now the signal crawls through two stages instead of one. Building a whole circuit out of NAND (and its mirror NOR) is therefore both smaller and faster than building it from AND and OR. Two tricks make it possible: pull a NOT out of a NAND, and rewrite an ordinary AND-OR circuit as all NANDs.
A NOT from a NAND
Give a NAND the same wire on both inputs and it becomes an inverter. Feeding
A to both inputs, the gate computes A NAND A, which is NOT (A AND A). Since A AND A is just A, that is NOT A. Tying one input high works too: A NAND 1 is NOT (A AND 1), and A AND 1 is A, so again NOT A.| A | A NAND A |
|---|---|
| 0 | 1 |
| 1 | 0 |
A NAND A, which is exactly NOT A.From an AND-OR circuit to all NANDs
Any function written as a sum of products (see truth tables, or Karnaugh maps for the minimal one) is a two-level circuit: one AND gate per product term, all feeding a single OR gate. To turn that AND-OR shape into pure NAND you push inversion bubbles around, using one fact and one law.
A bubble on a wire means invert. Put two bubbles on the same wire and they cancel: inverting twice returns the original signal (
NOT (NOT x) is x). So you may drop a cancelling pair of bubbles onto any wire without changing what the circuit computes. That freedom is the whole trick.- Start from the two-level AND-OR circuit: the AND gates on the left, their outputs feeding one OR gate on the right.
- On each wire between an AND output and the OR input, add a pair of bubbles, one at the AND's output and one at the OR's input. Two bubbles per wire cancel, so the function is untouched.
- Absorb each output bubble into its AND gate. An AND gate with a bubble on its output is a NAND. The whole first level is now NAND gates.
- Absorb the input bubbles into the OR gate. An OR gate with a bubble on every input equals a NAND, because De Morgan's law says
(NOT p) OR (NOT q)isNOT (p AND q), which is exactly what a NAND computes. The second level is now a NAND too. - Nothing is left but NANDs, and the output still computes the original sum of products. In short: replace every AND and the final OR with a NAND, and change nothing else.
Worked example
Take a two-term function (
A' means NOT A):F = (A ∧ B) ∨ ((¬A) ∧ C)
As an AND-OR circuit it is two AND gates, one for
A AND B and one for (NOT A) AND C, feeding one OR gate. Now apply the rule: swap each AND and the OR for a NAND. The first product becomes G1 = A NAND B. The second needs NOT A first, which is a NAND with its inputs tied (A NAND A), then G2 = (NOT A) NAND C. The OR becomes the final gate F = G1 NAND G2. Four NANDs, nothing else:F = (A NAND B) NAND ((A NAND A) NAND C)
| A | B | C | A' | G1 | G2 | F |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 1 | 1 | 0 |
| 0 | 0 | 1 | 1 | 1 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 | 1 | 0 |
| 1 | 1 | 0 | 0 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 0 | 1 | 1 |
A' is A NAND A; G1 and G2 are the first-level NANDs; F is the second-level NAND. Every F cell matches A·B + A'·C, so the all-NAND circuit computes the original sum of products. (This function is the 2-to-1 multiplexer: F follows C when A is 0, and B when A is 1.)Doing this by hand, three slips are common. Bubbles must go on in cancelling pairs: one stray bubble (an odd count on a wire) inverts the function. The trick assumes a clean two-level sum of products, AND gates feeding one OR; a deeper tangle of levels needs bubble-pushing stage by stage, not one blind swap. And
NOT A is not free: it costs a NAND of its own, so count it when you tally gates (a bare single-literal term like C likewise needs its own inverting NAND so the bubbles balance).Try it
Convert
F = A·B + C·D into a NAND-only circuit, then check the row A=B=1, C=D=0.Answer
Swap both ANDs and the OR for NANDs:
G1 = A NAND B, G2 = C NAND D, F = G1 NAND G2. For A=B=1, C=D=0: G1 = NAND(1,1) = 0, G2 = NAND(0,0) = 1, F = NAND(0,1) = 1, which matches A·B + C·D = 1 + 0 = 1. By De Morgan the circuit equals A·B + C·D on every row.Spot the fault
A1BZOUTX
Look at B
Float (Z)
Input
B was never wired, so its gate floats at Z rather than a real 0 or 1. A floating CMOS input leaves both the pull-up and pull-down partly on, so the output is indeterminate (X), not a clean logic level. Every gate input must be driven by something; tie an unused input to a fixed 0 or 1 rather than leaving it open.Frequently asked
What is a NAND gate?
A NAND (NOT-AND) gate outputs
0 only when both of its inputs are 1, and 1 in every other case. It does an AND and then inverts the result.Why is NAND called a universal gate?
Because every other logic gate can be built from NAND gates alone: NAND alone reproduces NOT, AND, OR, and XOR, and from those any logic function at all. That is why real chips lean on it.
How do you build a NAND gate from transistors?
Put two NMOS transistors in series as the pull-down (output goes
0 only when both inputs are 1) and two PMOS transistors in parallel as the pull-up (output goes 1 whenever either input is 0). Series-down, parallel-up is a CMOS NAND, just four transistors.What is the difference between NAND and NOR?
They are topological mirrors. NAND outputs
0 only when both inputs are 1 (parallel PMOS up, series NMOS down); NOR outputs 1 only when both inputs are 0 (series PMOS up, parallel NMOS down). Both are universal.How do you make a NOT gate from a NAND gate?
Tie both inputs of the NAND to the same wire. The gate then computes
A NAND A, which is NOT (A AND A), and since A AND A equals A, the output is NOT A. Tying one input high works too: A NAND 1 is also NOT A.How do you convert an AND-OR circuit into NAND gates?
Write the function as a sum of products (AND gates feeding one OR gate), then replace every AND gate and the final OR gate with a NAND gate and change nothing else. Adding a cancelling pair of inversion bubbles on each wire between the two levels leaves the function unchanged, and De Morgan's law turns the bubbled OR into a NAND, so the result is an all-NAND circuit computing the same function.
You've got the theory. Now build it from scratch and watch it work.
Build it in the lab →