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

XOR gate circuit diagram from AND, OR and NOT gates, live

An XOR gate can be built from basic gates as A'B + AB': two NOT gates make A' and B', two AND gates make the products A'B and AB', and an OR gate combines them. The output is 1 when exactly one input is 1. The same parts plus two more ANDs and an OR give XNOR = A'B' + AB.

This is the sum-of-products form read straight off the truth table. XOR is 1 in two rows: A = 0, B = 1, which is the product A'B, and A = 1, B = 0, which is AB'. OR the two products and you have XOR = A'B + AB', five gates in all. XNOR is 1 in the other two rows, A = B = 0 and A = B = 1, so XNOR = A'B' + AB, and it can share the two NOT gates. Another form, XOR = (A + B)(AB)', reads as "A or B, but not both" and uses an OR, a NAND and an AND. In CMOS a dedicated XOR takes fewer transistors than any of these, as in the CMOS XOR gate, and with one gate type only it is the four-NAND XOR or the five-NOR XOR. For the symbol, truth table and Boolean identities of the gate itself, see the XOR gate truth table; for the gate inside an adder, the half adder.

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, “XOR and XNOR from AND, OR and NOT gates”, https://digiwleea.wleeaf.dev/tools/build/xor-from-basic-gates/

What you need

Step by step

  1. Place inputs A and B and probes XOR and XNOR.
  2. Invert A and B with two NOT gates.
  3. XOR: AND A' with B, AND A with B', and OR the two results into XOR.
  4. XNOR: AND A' with B', AND A with B, and OR the two results into XNOR.
  5. Toggle A and B through 00, 01, 10 and 11: XOR is 1 only when they differ, XNOR only when they are equal.

XOR and XNOR from basic gates: truth table

ABA'BAB'XOR = A'B + AB'XNOR = A'B' + AB
000001
011010
100110
110001

At most one product term is 1 in any row, so the OR never has two 1s to merge. All four rows of both outputs are checked on the live circuit before the page is built.

You can also read the full theory in the lesson on the XOR 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 XOR and XNOR from AND, OR and NOT gates in the lab →

Frequently asked

How do you make an XOR gate using basic gates?

Use two NOT gates, two AND gates and one OR gate: XOR = A'B + AB'. The ANDs detect the two rows where the inputs differ, and the OR combines them.

How many basic gates are needed for an XOR gate?

Five in the sum-of-products form: two NOT, two AND and one OR. The form (A + B)(AB)' needs three: an OR, a NAND and an AND.

What is the Boolean expression of an XOR gate?

A XOR B = A'B + AB', which can also be written (A + B)(A' + B') or (A + B)(AB)'.

How do you make an XNOR gate using basic gates?

XNOR = A'B' + AB: two NOT gates, two AND gates and an OR gate, or an XOR followed by a NOT.

Why is XOR not a basic gate?

Because it can be built from AND, OR and NOT, the three gates that every Boolean function can be written with. It is still made as one gate in practice because it is used so often, in adders, comparators and parity circuits.