Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksBuild a CPUToolsOpen the lab →

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).

Live circuit: click the inputs to toggle them and watch the outputs update. It runs the real simulator, right here on the page.

Open this circuit in the lab →

Embed or cite this circuit

Free to embed on a course page, blog or worksheet: paste this code. The circuit stays live, and the small digiwleea badge links back here.

To cite it: digiwleea, “XNOR gate from NAND gates”, https://digiwleea.wleeaf.dev/tools/build/xnor-from-nand/

What you need

Step by step

  1. Place inputs A and B, five NAND gates and a probe Y.
  2. First gate: NAND A with B. Second and third: NAND A with that output, and NAND B with that output.
  3. Fourth gate: NAND the second and third outputs. That is A XOR B.
  4. Fifth gate: connect both inputs to the XOR and probe its output: NOT XOR, which is A XNOR B.

XNOR truth table

ABA XOR BY = A XNOR B
0001
0110
1010
1101

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.