LogicGates.org Open the simulatorSimulator
Roadmap

NAND, NOR and XNOR

Lesson 5 of 6 in this stage, about 12 minutes

Three gates with a NOT built in, and why one of them is enough to build a computer.

Three gates with a NOT built in

You have met four gates: AND, OR, NOT and XOR. The last three of the seven are not new ideas. Each is one of the gates you know with a NOT gate glued onto its output, and the names say so: NAND is "not AND", NOR is "not OR", and XNOR is "not XOR". In the symbol, that built-in NOT is the bubble from the NOT lesson, drawn on the nose of the AND, OR or XOR shape. To work any of them out, work out the plain gate first and then flip the answer.

NAND gate. Click the inputs.

out 1
ab out
0 0 1
0 1 1
1 0 1
1 1 0

NAND: the AND table turned upside down. AND has a single 1 in the bottom row; NAND has a single 0 there and 1 everywhere else. In words, NAND outputs 0 only when every input is 1.

NOR gate. Click the inputs.

out 1
ab out
0 0 1
0 1 0
1 0 0
1 1 0

NOR: the OR table flipped. OR has a single 0 in the top row; NOR has a single 1 there. NOR outputs 1 only when every input is 0. It is the gate for "none of them".

XNOR gate. Click the inputs.

out 1
ab out
0 0 1
0 1 0
1 0 0
1 1 1

XNOR: XOR flipped. XOR is 1 when the inputs differ, so XNOR is 1 when they are the same: 1 for 00 and 11, 0 for 01 and 10. That makes XNOR the "equal" gate. Feed it two bits and it answers the question "are these two bits the same?", which is the first step in comparing two numbers.

Worked example. What does a NOR gate output for inputs 1 and 0? And a NAND gate for 1 and 1?

NOR is OR then NOT. OR of 1 and 0: at least one is 1, so 1. Flip it: 0. The NOR gate outputs 0. NAND is AND then NOT. AND of 1 and 1: both are 1, so 1. Flip it: 0. The NAND gate outputs 0. Check both against the tables above: the 10 row of NOR and the 11 row of NAND are both 0.

Common mistake: flipping the inputs instead of the output

NAND is not "AND of the flipped inputs". The NOT is on the output, after the AND has done its work. NAND of 1 and 1 is NOT(1 AND 1) = NOT 1 = 0. If you flipped the inputs first you would get 0 AND 0 = 0, and that happens to agree here, but try 1 and 0: NAND gives NOT(0) = 1, while flipping first gives 0 AND 1 = 0. Always gate first, then flip.

Why NAND matters more than it looks

NAND seems like an afterthought, an AND with an extra step. It is the opposite. NAND on its own can build every other gate, and so every circuit in this course, without any help. A gate with that property is called universal. NOR is universal too. None of AND, OR, XOR or NOT is.

Here are the three constructions, and each is short enough to check against a truth table.

NOT from NAND. Connect both inputs of a NAND gate to the same wire. The gate only ever sees 00 or 11. NAND of 00 is 1 and NAND of 11 is 0, so a 0 in gives 1 out and a 1 in gives 0 out. That is NOT.

A NAND gate with both inputs tied to a. It behaves as NOT.

out 1
a out
0 1
1 0

AND from NAND. NAND is AND with a flip on the end, so undo the flip: feed the NAND's output into a second NAND wired as a NOT. Two flips cancel, and what is left is AND. Two gates.

OR from NAND. Flip each input with its own NAND-as-NOT, then NAND the two results together. Three gates. Try it below, and compare its table with the OR gate from earlier: they match row for row. Why inverting both inputs of an AND-with-a-flip should give OR is a rule with a name, and the next stage is about it; for now it is enough that the table says so.

NOT a and NOT b into a NAND. This circuit behaves exactly like OR: compare the table with the OR gate's.

out 0
ab out
0 0 0
0 1 1
1 0 1
1 1 1
Why?: why are chips built from NAND?

A factory that has to make one kind of gate well is in a better position than one that has to make seven. In the transistor technology used for nearly every chip today, a NAND gate is four transistors and an AND gate is six, because the AND is built as a NAND with an inverter on the end. So the "simpler" gate is the more expensive one, and designers let the flips fall where they may and use NANDs and NORs everywhere. The tools then take a design written with AND and OR and turn it into NAND and NOR automatically.

What to remember

  • NAND, NOR and XNOR are AND, OR and XOR with a NOT on the output; the bubble on the symbol shows it.
  • To work one out, do the plain gate first and then flip the answer.
  • NAND outputs 0 only when every input is 1; NOR outputs 1 only when every input is 0.
  • XNOR outputs 1 when its two inputs are equal. It is the "same?" gate.
  • NAND alone can build NOT, AND and OR, so it can build anything. That is why chips are made of it.

Check yourself

Get 5 right in a row and the lesson is done. A wrong answer costs the run, not the lesson.

0 right in a row. 0 / 0 this visit

Which gate has this truth table?

ab Q
0 0 0
0 1 1
1 0 1
1 1 1

Already know this? and come back to the quiz any time.

Go deeper