XNOR gate using NAND gates: five NANDs, live
An XNOR gate can be built from five NAND gates: the classic four-NAND XOR circuit, followed by a fifth NAND with both inputs tied together, which works as a NOT and inverts XOR into XNOR. Y is 1 exactly when A and B are equal.
NAND is a universal gate: every other gate can be made from it alone (see NAND as a universal gate). The XOR from four NANDs computes n1 = NAND(A, B), then NAND(A, n1) and NAND(B, n1), and NANDs those two: the result is 1 when A and B differ. A NAND with both inputs on the same signal outputs NOT of it, so one more NAND turns XOR into XNOR. Five gates is the minimum with 2-input NANDs only; with NOR gates, XNOR takes four (the first four gates of the XOR from NOR circuit).
Open this circuit in the lab →
What you need
- 1× NAND: n1 = NAND(A, B)
- 2× NAND: NAND(A, n1) and NAND(B, n1)
- 1× NAND: XOR = NAND of the two
- 1× NAND: inputs tied: NOT XOR = XNOR
Step by step
- Place inputs
AandB, five NAND gates and a probeY. - First gate: NAND A with B. Second and third: NAND A with that output, and NAND B with that output.
- Fourth gate: NAND the second and third outputs. That is A XOR B.
- Fifth gate: connect both inputs to the XOR and probe its output: NOT XOR, which is A XNOR B.
XNOR truth table
| A | B | A XOR B | Y = A XNOR B |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
All four rows of the live circuit are checked before the page is built. Y is 1 on the two rows where A equals B.
You can also read the full theory in the lesson on the NAND gate. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.
More builds: Universal gates: NAND only, NOR only
All 246 build guides, by topic
Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab, with the free theory reference alongside.
Open the XNOR gate from NAND gates in the lab →Frequently asked
How many NAND gates are needed to make an XNOR gate?
Five 2-input NAND gates: four to make XOR and one, with its inputs tied together, to invert it.
How do you make XNOR from NAND gates?
Build XOR from four NANDs: n1 = NAND(A, B), then NAND(A, n1) and NAND(B, n1), then NAND those two. Feed the XOR into a fifth NAND with both inputs connected, which acts as a NOT gate.
Is it cheaper to make XNOR from NOR gates?
Yes, by one gate: four NOR gates make XNOR directly, and a fifth NOR inverts it into XOR.