Skip to content

Digital Logic

Why is NAND called a universal gate?

NAND is called a universal gate because every other logic gate, and so every digital circuit, can be built from NAND gates alone. Tie its inputs together and it's a NOT. Follow it with a NOT and it's an AND. Put NOTs on its inputs and, by De Morgan's laws, it's an OR. Four of them make an XOR.

NAND in one line

NAND is AND followed by NOT: its output is 0 only when both inputs are 1, and 1 for every other row.

ABNAND
001
011
101
110

Every gate from NANDs

NOT (1 NAND). Join both inputs to A. Then A AND A is just A, and the NOT flips it:

NAND(A, A) = NOT A

AND (2 NANDs). A NAND gives NOT (A AND B). A second NAND, wired as a NOT, flips it back.

OR (3 NANDs). Make NOT A and NOT B with two NANDs, then NAND those. NAND is 0 only when both its inputs are 1, which is when A and B are both 0: exactly the one row where OR is 0.

XOR (4 NANDs). Call the first NAND of A and B, n. NAND A with n, NAND B with n, then NAND those two results. All four rows come out 1 when A and B differ.

Live experiment

One brick builds them all

Pick NOT, AND, OR or XOR and it's wired from NAND gates alone: one, two, three or four of them. Flip A and B through every row and compare what the NANDs give with the real gate's table. Every row matches.

Try it yourself: free lesson

“NAND is enough” is lesson 1 of 6 in Nand Narrows, Digital Logic World 2. Free with an account. Lessons unlock in order, so you’ll do the 7 before it first.

Why that matters

Once you have NOT, AND and OR, you can build any truth table: write one AND term for each row that should give 1, and OR the terms together. Since NAND makes all three, NAND alone makes anything: adders, flip-flops, whole processors. NOR is universal in exactly the same way, starting from NOR(A, A) = NOT A.

Why chips favour it

In CMOS, the way almost all chips are made, a two-input NAND is four transistors, and the inverting gates are the natural, fast ones. An AND is really a NAND plus a NOT, six transistors. So chip tools rewrite designs into NANDs and NORs, pushing NOTs around with De Morgan's laws until each gate is one of the cheap ones. The 7400, one of the first logic chips of the 1960s, held four NAND gates, and the Apollo Guidance Computer that flew to the Moon was built almost entirely from NOR gates.

Free lesson

Now build it yourself

Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.

Try it yourself: free lesson

“NAND is enough” is lesson 1 of 6 in Nand Narrows, Digital Logic World 2. Free with an account. Lessons unlock in order, so you’ll do the 7 before it first.

Or start from the very first lesson, no account needed

Practice questions

Three quick questions from the lessons. Pick an answer to check it.

  1. Question 1 of 3A NAND with both inputs tied to A gives…
    Show the answer

    Answer: NOT A. NAND(A, A) is NOT (A AND A), which is NOT A.

    • Why not “A”? With both inputs equal to A, the AND part gives A and the NOT flips it, so the output is the opposite of A.
    • Why not “Always 1”? NAND is 0 when both inputs are 1, so whenever A is 1 the output is 0, not always 1.
    • Why not “Always 0”? NAND is 1 when either input is 0, so whenever A is 0 the output is 1, not always 0.
  2. Question 2 of 3Two NANDs in a row, the second with tied inputs, make…
    Show the answer

    Answer: AND. The first is AND-then-NOT, the second is a NOT: the NOTs cancel and AND is left.

    • Why not “OR”? OR needs its inputs inverted before the gate. Here the second NAND inverts after, which undoes the first one's NOT.
    • Why not “XOR”? XOR takes four NANDs. Two in a row like this only cancel the first one's NOT, leaving AND.
    • Why not “NOR”? NOR would need an OR inside. Two NANDs this way give AND's single 1 for 1 and 1.
  3. Question 3 of 3NAND's output is 0 for…
    Show the answer

    Answer: Only A = 1 and B = 1. AND is 1 only for 11, so NAND, its opposite, is 0 only for 11. Every other row is 1.

    • Why not “Only A = 0 and B = 0”? With both inputs at 0 the AND part is 0, so NAND gives 1. Only NOR is 0 there and nowhere else is 1.
    • Why not “Never”? NAND does reach 0, on exactly one row: A = 1 and B = 1.
    • Why not “Any input at 1”? One input at 1 isn't enough: the AND part needs both, so NAND stays 1 unless both are 1.
Keep practising: free lesson

“NAND is enough” is lesson 1 of 6 in Nand Narrows, Digital Logic World 2. Free with an account. Lessons unlock in order, so you’ll do the 7 before it first.

Questions people ask

What does universal gate mean?

A gate type from which every other logic function can be built, with nothing else. NAND and NOR are the two universal gates: any truth table at all can be made from enough of either one.

How many NAND gates make an XOR?

Four. The first NANDs A and B; the second NANDs A with that result, the third NANDs B with it, and the fourth NANDs the second and third together. The output is 1 exactly when A and B differ.

Is NOR also a universal gate?

Yes. A NOR with its inputs tied is a NOT, and the same tricks with De Morgan's laws build AND, OR and the rest. The Apollo Guidance Computer was built almost entirely from NOR gates.

Why are NAND gates used so much in chips?

In CMOS a two-input NAND takes just four transistors and switches quickly. An AND is a NAND followed by a NOT, six transistors, so designers build logic from NAND and NOR and let the inverting work for them.

Every topic