NAND Bricks

How to build an OR gate from NAND gates

An OR gate takes three NAND gates. Invert A and B with two NAND gates wired as NOT gates, then feed both into a third NAND. The output is 1 whenever A or B (or both) is 1.

Inputs
1NAND2NAND3NANDA1B01Q
Click the inputs to try every combination. Green wires carry 1 and red wires carry 0. The small numbers match the steps below.
Open this circuit in NAND BricksLoads it as a new board with its truth table, ready to run.

The formula

Q = NAND(NOT A, NOT B) = NAND(NAND(A, A), NAND(B, B))

How it works

This one rests on De Morgan's law: A OR B is the same as NOT (NOT A AND NOT B). In words: "at least one is on" means "it is not the case that both are off".

NOT (something AND something) is exactly what a NAND computes. So invert each input, NAND them, and you have OR.

The last gate outputs 0 only when both of its inputs are 1, which happens only when A and B are both 0. Every other case gives 1.

Gate by gate

  1. A NOT gate on A. Outputs 1 when A is 0.
  2. A NOT gate on B. Outputs 1 when B is 0.
  3. NANDs the two inverted inputs. Outputs 0 only when A and B are both 0, so the result is A OR B.

Truth table

ABQ
000
011
101
111

Why 3 NAND gates?

Three is the fewest possible. An exhaustive search over every one- and two-gate circuit finds none that make OR.

Where it's used

OR combines conditions: "carry out if either half adder carried" in a full adder, or "interrupt if any device asks".