Lessons in IT Basics

Hardware Basics · Lesson 6 · 7 min read

Building an OR Gate

By the end of this lesson

  • Build an OR gate using only NAND and NOT primitives
  • Recognize the symmetry between AND and OR via inversion

The last gate you built was AND — a NAND with its output flipped one extra time. The trick was small but elegant: a single NOT on the output, and an AND falls out.

OR is going to feel similar, but the symmetry hides in a different place.

Here is the thing to notice. A NAND tells you when its inputs are not both on. So when both inputs are on, the NAND turns off. Every other case, it stays on. Now flip your point of view — what if I flipped both inputs before they reached the NAND, instead of flipping the output afterwards?

If A and B both feed into a NAND, it goes off when both are on. But if I send “not A” and “not B” into a NAND instead, it goes off only when both of those are on — which means only when both A and B are off. Every other case (at least one of A or B is on), the NAND stays on. That is exactly what an OR gate does.

The editor below has only NAND and NOT in its palette. Build it.

Your task

Build a circuit that turns the two inputs into an OR gate. The output Y should be on whenever A or B (or both) is on. You have NAND and NOT available.

Interactive circuit builder — visual interaction required. The current circuit’s truth table is shown to the right of the canvas.

Palette

NAND

NOT

A
B
Y
Drag a gate from the palette. Click ports to wire.

Live

updating
ABY
000
010
100
110

Target

ABY
000
011
101
111
Wire it up to match the target.

This is your first taste of a pattern that runs through all of digital logic: AND and OR are tied to each other through inversion. Flip the inputs of a NAND and you get OR. Flip the output of a NAND and you get AND. The same primitive, looked at two different ways, gives you both gates. (Mathematicians have a name for this relationship, but the elegance lands harder when you discover it by building rather than by being told.)

Next: XOR. The trickiest of the standard gates, and the most useful for what comes after — addition, comparison, encryption. It’s the first gate that needs more than one or two NANDs to build.