NAND Bricks

How to build a half adder from NAND gates

A half adder takes five NAND gates. The four-NAND XOR produces the sum bit, and one more NAND, wired as a NOT on the XOR's first gate, produces the carry. It adds two one-bit numbers: 1 + 1 gives sum 0, carry 1.

Inputs
1NAND2NAND3NAND4NAND5NANDA1B10Sum1Carry
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

Sum = XOR(A, B), Carry = NOT(NAND(A, B))

How it works

Adding two single bits has four cases: 0+0 = 0, 0+1 = 1, 1+0 = 1, and 1+1 = 10 in binary. The low digit (the sum) is 1 when exactly one input is 1, which is XOR. The high digit (the carry) is 1 only when both are 1, which is AND.

Building XOR and AND separately would cost 4 + 2 = 6 NAND gates. But the XOR's first gate already computes NAND(A, B), and AND is just that, flipped. So the carry only needs one extra gate wired as a NOT on it.

It is called a "half" adder because it has no input for a carry coming in from a lower bit. The full adder in the next guide adds that.

Gate by gate

  1. NAND(A, B). Shared: the XOR uses it, and so does the carry.
  2. NAND(A, n1). Part of the XOR.
  3. NAND(n1, B). Part of the XOR.
  4. The sum: NANDs the two middle results into A XOR B.
  5. The carry: a NOT on the first gate, giving A AND B.

Truth table

ABSumCarry
0000
0110
1010
1101

Why 5 NAND gates?

Five is the fewest possible. Reusing the XOR's first gate saves one over building XOR and AND separately, and an exhaustive search confirms no four-gate circuit makes both outputs.

Where it's used

Half adders handle the lowest bit of an addition, where there is no carry coming in. Two of them plus an OR make a full adder.