Watch on Instagram

Circuit Bytes · Episode 51 · Electronics · Logic gates

"NAND: the universal gate"

NAND is an AND gate with its answer flipped. Tie its inputs together and it becomes NOT; add that NOT after a NAND and you get AND; flip both inputs first and you get OR. Since AND, OR and NOT can build any logic, NAND alone can too, and a CMOS NAND takes only four transistors.

Posted · About a 1 minute watch, 3 minute read · Take the quiz

NAND means NOT AND

Episode 49 met the AND gate: its output is 1 only when both inputs are 1. A NAND gate (short for NOT AND) does the same check and then flips the answer. On a schematic it is the AND symbol with a small circle (a "bubble") on its output tip, the same "flip it" bubble the NOT gate wears.

| A | B | NAND output | |---|---|---| | 0 | 0 | 1 | | 0 | 1 | 1 | | 1 | 0 | 1 | | 1 | 1 | 0 |

So a NAND outputs 0 only when both inputs are 1. Anything else gives 1.

Building NOT, AND and OR from NAND

  • NOT: tie the two inputs together so they always match. A 0 in means both inputs are 0, so the output is 1. The gate now just flips its single input.
  • AND: put a NOT (a NAND with tied inputs) after a NAND. The NAND flips the AND answer, and the NOT flips it back, so the two flips cancel and you are left with plain AND.
  • OR: flip each input first (two NANDs with tied inputs), then feed both into a third NAND. The output is 1 whenever at least one original input is 1, which is exactly OR. (This trick is known as De Morgan's law.)

Why "universal"?

Any logic rule you can write as a truth table can be built from AND, OR and NOT. Since NAND can make all three, NAND gates alone can build any logic circuit. That property is called functional completeness, and it is why NAND is nicknamed the universal gate. The free Nand2Tetris course takes this literally: it starts with a single NAND gate and builds up to a working computer.

Cheap in transistors

In CMOS (episode 50), a two-input NAND takes just four transistors: two P-type transistors side by side (in parallel) linking the output to the supply, and two N-type transistors stacked (in series) linking it to ground. Both N-types must be on, meaning both inputs 1, before the output is pulled to 0. A CMOS AND needs six transistors (a NAND plus an inverter), which is one reason chip designers like NAND as a building block.

Try it yourself

On paper, draw the OR circuit from this lesson: two NANDs with tied inputs feeding a third NAND. Write a small truth table and trace all four input pairs (0 0, 0 1, 1 0, 1 1) through the three gates, noting the value on every wire. Does the last column match the OR truth table from episode 49? Then count: if each NAND is four transistors, how many transistors does your NAND-built OR use?

Good to know

  • A NAND gate outputs 0 only when all of its inputs are 1; it is the complement of AND.
  • NAND is functionally complete: tied inputs give NOT, NAND followed by NOT gives AND, and NOT on each input followed by NAND gives OR (De Morgan's law).
  • NOR is universal too. The Apollo Guidance Computer was built almost entirely from NOR gates.
  • A two-input CMOS NAND uses four transistors (two p-channel in parallel to the supply, two n-channel in series to ground); a CMOS AND needs six.
  • "Build a whole computer" also needs memory, which is made of gates wired in feedback loops (coming in episode 53).

Answer to the comment question

A NAND gate gets a 1 and a 0. Its output goes through a NOT gate. What comes out? 0. The NAND gate only outputs 0 when both inputs are 1. Here one input is 0, so the NAND outputs 1. The NOT gate then flips that 1 into a 0. (A NAND followed by a NOT is just an AND gate, and AND of 1 and 0 is 0.)

Test your knowledge

Quick quiz: "NAND: the universal gate"

4 multiple-choice questions. Pick one answer for each, then check how you did.

1When does a two-input NAND gate output 0?
2What do you get if you tie a NAND gate's two inputs together?
3How do you build an OR gate from NAND gates?
4Why is NAND called the universal gate?

Sources

  • All About Circuits textbook, Vol. IV Digital, chapter 3, "Multiple-input Gates": the NAND gate and its truth table
  • All About Circuits textbook, Vol. IV Digital, chapter 3, "CMOS Gate Circuitry": the four-transistor CMOS NAND
  • Nand2Tetris (Nisan and Schocken, The Elements of Computing Systems), "Project 1: Boolean Logic": building NOT, AND, OR and every other chip from NAND alone
  • Wikipedia, "NAND logic": functional completeness; NOT, AND and OR built from NAND gates (cross-check only)

Video transcript

Could you build a whole computer from just one kind of gate?

Meet NAND, short for NOT AND. It's an AND gate with its answer flipped.

It outputs zero only when both inputs are one. Anything else gives one.

Tie its two inputs together and it becomes a NOT gate: zero in, one out.

Put that NOT after a NAND and the flips cancel. Now you have AND.

Flip each input first, then NAND them, and you get OR. AND, OR and NOT build any logic, so NAND alone can too. That's why it's universal.

A CMOS NAND needs only four transistors.

A NAND gate gets a one and a zero. Its output goes through a NOT gate. What comes out? Comment your answer below!

That's your byte.

More from Circuit Bytes

All Circuit Bytes lessons