How to build an XNOR gate from NAND gates
An XNOR gate takes five NAND gates: the four-gate XOR, followed by a NAND wired as a NOT. The output is 1 when A and B are equal, both 0 or both 1.
- 5NAND gates
- Yesfewest possible
- 2inputs
- 1output
Inputs
Open this circuit in NAND BricksLoads it as a new board with its truth table, ready to run.
The formula
Q = NOT(XOR(A, B))
How it works
XNOR is the equality gate. It answers "are these two bits the same?", which makes it the opposite of XOR.
So the build is the XOR from the previous guide plus one more NAND that inverts its answer.
Gate by gate
- N = NAND(A, B), shared by the next two gates.
- NAND(A, N). 0 only when A is 1 and B is 0.
- NAND(N, B). 0 only when B is 1 and A is 0.
- Combines them into A XOR B.
- A NOT gate that flips XOR into XNOR. 1 when A equals B.
Truth table
| A | B | Q |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Why 5 NAND gates?
Five is the fewest possible. An exhaustive search shows no four-gate circuit makes XNOR, even though four is enough for XOR. Flipping the answer really does cost a gate here.
Where it's used
Chain XNORs together with ANDs and you get an equality comparator: is this 8-bit number the same as that one?