Skip to main content
Be Bitwise

XOR, NAND, and NOR

Logic Gates · Foundations track

3 min read

In this module

Beyond the Basics

Now that you know AND, OR, and NOT, you're ready for three more gates. Each one is built by combining the fundamentals, but they show up so often in circuit design that they've earned their own names and symbols.

The XOR Gate

XOR stands for exclusive OR. It outputs 1 when the inputs are different and 0 when they are the same.

ABA XOR B
000
011
101
110

The big difference from OR: when both inputs are 1, OR outputs 1 and XOR outputs 0. XOR is essentially asking, "Is exactly one of these true?" That single question turns out to be wildly useful for binary addition and error detection.

The NAND Gate

NAND means NOT AND. Take the output of an AND gate and invert it.

ABA NAND B
001
011
101
110

A NAND gate outputs 0 in exactly one case, when both inputs are 1. The mirror image of AND.

The NOR Gate

NOR means NOT OR. Take the output of an OR gate and invert it.

ABA NOR B
001
010
100
110

A NOR gate outputs 1 only when both inputs are 0.

Universal Gates

NAND and NOR are called universal gates because you can build any other logic gate using only NAND gates or only NOR gates. That has practical weight too. In CMOS, the transistor technology inside almost every modern chip, NAND and NOR are among the cheapest gates to build: an AND gate is really a NAND with an inverter bolted on. The Apollo Guidance Computer took the idea to its limit and was built from NOR gates alone.

Why Universal Gates Matter

Imagine a factory that can only produce one type of gate. If that gate is NAND, you can still build AND, OR, NOT, XOR, and every other gate by wiring multiple NANDs together. Connect both inputs of a NAND to the same signal and you've got a NOT gate. Chain two NANDs and you get an AND. That universality is one of the most elegant ideas in digital design.

Here are AND and OR built from nothing but NANDs. In each diagram, a NAND with both inputs tied to the same wire is acting as a NOT.

The AND version is easy to believe: NAND is AND followed by NOT, so a second NOT cancels the first. The OR version is less obvious, so check it row by row:

ABNOT ANOT B(NOT A) NAND (NOT B)
00110
01101
10011
11001

The last column matches the OR truth table exactly. The next lesson gives you the rule behind it, De Morgan's theorem, so you won't need a table every time.

Next we step back from individual gates and pick up the mathematical language that describes how they combine: Boolean algebra.