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.
- 5NAND gates
- Yesfewest possible
- 2inputs
- 2outputs
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
- NAND(A, B). Shared: the XOR uses it, and so does the carry.
- NAND(A, n1). Part of the XOR.
- NAND(n1, B). Part of the XOR.
- The sum: NANDs the two middle results into A XOR B.
- The carry: a NOT on the first gate, giving A AND B.
Truth table
| A | B | Sum | Carry |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
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.