XOR gate: truth table, symbol and Boolean expression

Truth table, symbol and algebraic form for A ⊕ B, the difference detector.

The XOR gate

XOR gate with 2 inputs, drawn with IEEE 91-1984 distinctive shapes Logic gate schematic. 2 inputs: A and B. 1 gate: 1 XOR. The output F is driven by an XOR gate. The longest signal path passes through 1 gate. A B F
XOR gate with 2 inputs, drawn with IEC 60617-12 rectangular symbols Logic gate schematic. 2 inputs: A and B. 1 gate: 1 XOR. The output F is driven by an XOR gate. The longest signal path passes through 1 gate. A B =1 F
Distinctive shape — ANSI/IEEE Std 91-1984Rectangular shape — IEC 60617-12 (constructed metrics)F = A ⊕ B at 2 inputs

IEC 60617-12:1997 is a paid standard and its per-symbol dimensions are not public. These rectangular symbols follow the published module-grid construction (module M = 6.5 units, so 4M = 26 matches the IEEE body height; line width M/10; qualifying symbol top-centre; connection pitch 2M; negation circle radius M/2 tangent outside the outline). The shapes and qualifying symbols are standard; the exact metrics are our construction, not a quotation.

Circuit description

Logic gate schematic. 2 inputs: A and B. 1 gate: 1 XOR. The output F is driven by an XOR gate. The longest signal path passes through 1 gate.

Inputs
1
1

Output F0

Notation used on this page
Positive logic
1 = HIGH = asserted, 0 = LOW = deasserted. An active-low signal is written with an overbar in figures and a trailing _n in copyable text, for example CLR_n.
Operators
· AND (also written by juxtaposition, AB) · + OR · ′ complement (postfix; an overbar in figures) · ⊕ XOR · ⊙ XNOR · ↑ NAND (Sheffer stroke) · ↓ NOR (Peirce arrow).
Precedence, highest first
( ) then ′ then · (including juxtaposition) then ⊕ and ⊙ then ↑ and ↓ then +. The parser echoes the fully parenthesised reading back, and warns without blocking when ⊕, ↑ or ↓ appears un-parenthesised beside · or +, because textbooks disagree there.
Truth-table row order
Binary counting order from all-zeros to all-ones. The first-listed variable is the most significant bit. Row index k is the integer value of the input vector, and the row is labelled mₖ.
Minterms and maxterms
Σm(…) lists the rows where F = 1. ΠM(…) lists the rows where F = 0. Mᵢ complements a variable wherever bit i is 1 — the opposite way round from mᵢ.
Symbol standards
IEEE means ANSI/IEEE Std 91-1984 with its 91a-1991 supplement — the distinctive shapes. IEC means IEC 60617-12 — the rectangular shapes with a qualifying symbol. The header toggle switches every figure on the page between them.
Symbol-set toggle
Both symbol standards are in this page’s HTML. The toggle in the header chooses which one is drawn, before the first frame is painted, and it changes nothing else on the page — not a truth table, not a gate count, not an answer.

Evaluation

F = A ⊕ B

F = 1 ⊕ 1 = 0

XOR outputs 1 when an odd number of its inputs is 1 — for two inputs, when exactly one is 1.

This is row 4 of 4 — minterm m₃ (A B = 11).

Truth table

Truth table for F = A ⊕ B. Select a row to set the inputs to it.
kABF
000
011
101
110

Canonical forms

Minterms
Σm(1, 2)
Maxterms
ΠM(0, 3)
Canonical sum of products
F = A′ · B + A · B′
Canonical product of sums
F = (A + B) · (A′ + B′)

mk is the row where F = 1 and Mk the row where F = 0. Mk complements a variable wherever bit k is 1 — the opposite way round from mk.

Karnaugh map

The map for this function is 2 variables, 2 of its 4 cells filled with 1 — cells m₁, m₂.

Karnaugh map solver group this function on a Karnaugh map, with this function carried across.

De Morgan equivalent

A ⊕ B = A′ ⊕ B′

An XOR body with bubbles on both inputs — they cancel. A bubble on one input, or on the output, turns it into an XNOR.

Both sides of A ⊕ B = A′ ⊕ B′, column by column.
ABA ⊕ BA′ ⊕ B′
0000
0111
1011
1100

The two columns agree on all 4 rows.

XOR from NAND gates only

  1. n1 = NAND(A, B)= A ↑ B
  2. n2 = NAND(A, n1)= A ↑ (A ↑ B)
  3. n3 = NAND(B, n1)= B ↑ (A ↑ B)
  4. n4 = NAND(n2, n3)= A ↑ (A ↑ B) ↑ (B ↑ (A ↑ B))

4 NANDs3 levels4 gates, 3 levels. Verified equivalent to the gate over all 4 input combinations.

Note:Four is the minimum for NAND. XNOR needs five — the asymmetry is exact and is the other way round for NOR.

XOR from NOR gates only

  1. n1 = NOR(A, B)= A ↓ B
  2. n2 = NOR(A, A)= A ↓ A
  3. n3 = NOR(B, B)= B ↓ B
  4. n4 = NOR(n2, n3)= A ↓ A ↓ (B ↓ B)
  5. n5 = NOR(n1, n4)= A ↓ B ↓ (A ↓ A ↓ (B ↓ B))

5 NORs3 levels5 gates, 3 levels. Verified equivalent to the gate over all 4 input combinations.

Note:The alternative is the 4-NOR XNOR followed by a fifth NOR used as an inverter, which is one level deeper than the direct build shown here.

Cost

12 transistorsTwelve transistors in fully static CMOS, or six in a transmission-gate implementation. XOR is expensive in silicon relative to NAND.

  • 74HC86quad 2-input XOR
Building each two-input gate from one primitive. Every count is measured from the netlist that draws it and verified by exhaustive simulation.
TargetNAND gatesNAND levelsNOR gatesNOR levels
buffer2222
NOT1111
AND2232
NAND1143
OR3222
NOR4311
XOR4353
XNOR5443
Note:XOR is cheaper in NAND (4 against 5) and XNOR is cheaper in NOR (4 against 5). The two four-gate builds are structural duals: swap every NAND for a NOR and the function complements.

What the XOR gate does

An XOR gate outputs 1 when an odd number of its inputs is 1. For two inputs that is the same as “exactly one input is 1”.

Algebraically it is F = A ⊕ B, which expands to F = A′ · B + A · B′ = (A + B) · (A · B)′ = (A + B) · (A′ + B′). For n inputs, F = A₁ ⊕ A₂ ⊕ … ⊕ Aₙ — 1 when an odd number of inputs is 1.

  • Commutative. A ⊕ B = B ⊕ A
  • Associative. (A ⊕ B) ⊕ C = A ⊕ (B ⊕ C) — unlike NAND and NOR, so a 3-input XOR cascade is well defined.
  • Identity. A ⊕ 0 = A
  • Controlled inverter. A ⊕ 1 = A′
  • Self-cancelling. A ⊕ A = 0, A ⊕ A′ = 1, and A ⊕ B ⊕ B = A
  • Bubble pair. A ⊕ B = A′ ⊕ B′ — two input bubbles cancel.
  • Complement. (A ⊕ B)′ = A ⊙ B = A′ ⊕ B

XOR gate truth table

XOR gate with 2 inputs: F = A ⊕ B. Σm(1, 2) · ΠM(0, 3)
kABF
0000
1011
2101
3110
XOR gate with 3 inputs: F = A ⊕ B ⊕ C. Σm(1, 2, 4, 7) · ΠM(0, 3, 5, 6)
kABCF
00000
10011
20101
30110
41001
51010
61100
71111
XOR gate with 4 inputs: F = A ⊕ B ⊕ C ⊕ D. Σm(1, 2, 4, 7, 8, 11, 13, 14) · ΠM(0, 3, 5, 6, 9, 10, 12, 15)
kABCDF
000000
100011
200101
300110
401001
501010
601100
701111
810001
910010
1010100
1110111
1211000
1311011
1411101
1511110

Boolean expression and canonical forms

At 2 inputs the function is F = A ⊕ B, with Σm(1, 2) and ΠM(0, 3). Expanded to canonical form that is F = A′ · B + A · B′ as a sum of products and F = (A + B) · (A′ + B′) as a product of sums.

Canonical form is unique once the variable order is fixed; minimal form is not. The minterm list is the shortest complete statement of the function and is what the Karnaugh map solver and the Quine–McCluskey solver both start from.

XOR gate symbol

Distinctive shape — ANSI/IEEE Std 91-1984

The distinctive-shape set draws the function as a body shape: a flat back with a semicircular nose is AND, a curved back with a pointed nose is OR, a triangle is a buffer, and an extra concave arc behind an OR body is XOR. A bubble on the output inverts the function; a bubble on an input inverts that input before the function is applied; two bubbles on one wire cancel.

The published proportions fix the AND, OR, XOR and bubble geometry but not the apex ratio of the buffer and inverter triangle. We use an apex 19 units from the base so the triangle matches the AND body width on the same sheet; the equilateral alternative, 13√3 ≈ 22.52, is equally defensible.

Rectangular shape — IEC 60617-12 (constructed metrics)

The rectangular set draws every gate as the same rectangle and puts a qualifying symbol in it: & for AND, ≥1 for OR, =1 for two-input exclusive-OR, 1 for a buffer or inverter. Negation is a circle tangent to the outline. Because every body is the same shape, the qualifying symbol is the whole of the information.

De Morgan equivalent symbol

A ⊕ B = A′ ⊕ B′

An XOR body with bubbles on both inputs — they cancel. A bubble on one input, or on the output, turns it into an XNOR.

De Morgan equivalent of the XOR gate, A ⊕ B, drawn with IEEE 91-1984 distinctive shapes Logic gate schematic. 2 inputs: A and B. 3 gates: 2 NOT and 1 XOR. The output F is driven by an XOR gate. The longest signal path passes through 2 gates. A B F
De Morgan equivalent of the XOR gate, A ⊕ B, drawn with IEC 60617-12 rectangular symbols Logic gate schematic. 2 inputs: A and B. 3 gates: 2 NOT and 1 XOR. The output F is driven by an XOR gate. The longest signal path passes through 2 gates. A B 1 1 =1 F
Distinctive shape — ANSI/IEEE Std 91-1984Rectangular shape — IEC 60617-12 (constructed metrics)the equivalent circuit, with the bubbles drawn as inverters

IEC 60617-12:1997 is a paid standard and its per-symbol dimensions are not public. These rectangular symbols follow the published module-grid construction (module M = 6.5 units, so 4M = 26 matches the IEEE body height; line width M/10; qualifying symbol top-centre; connection pitch 2M; negation circle radius M/2 tangent outside the outline). The shapes and qualifying symbols are standard; the exact metrics are our construction, not a quotation.

Circuit description

Logic gate schematic. 2 inputs: A and B. 3 gates: 2 NOT and 1 XOR. The output F is driven by an XOR gate. The longest signal path passes through 2 gates.

Matching a bubbled output to a bubbled input lets a reader cancel the pair by eye and read the circuit’s intent, which is why the equivalent symbol is worth drawing at all.

Building a XOR gate from NAND gates only

  1. n1 = NAND(A, B)= A ↑ B
  2. n2 = NAND(A, n1)= A ↑ (A ↑ B)
  3. n3 = NAND(B, n1)= B ↑ (A ↑ B)
  4. n4 = NAND(n2, n3)= A ↑ (A ↑ B) ↑ (B ↑ (A ↑ B))

4 NANDs3 levels4 gates, 3 levels. Verified equivalent to the gate over all 4 input combinations.

Note:Four is the minimum for NAND. XNOR needs five — the asymmetry is exact and is the other way round for NOR.

Building a XOR gate from NOR gates only

  1. n1 = NOR(A, B)= A ↓ B
  2. n2 = NOR(A, A)= A ↓ A
  3. n3 = NOR(B, B)= B ↓ B
  4. n4 = NOR(n2, n3)= A ↓ A ↓ (B ↓ B)
  5. n5 = NOR(n1, n4)= A ↓ B ↓ (A ↓ A ↓ (B ↓ B))

5 NORs3 levels5 gates, 3 levels. Verified equivalent to the gate over all 4 input combinations.

Note:The alternative is the 4-NOR XNOR followed by a fifth NOR used as an inverter, which is one level deeper than the direct build shown here.

Where the XOR gate is used

XOR is the most useful gate on this list. The half-adder sum is S = A ⊕ B with carry C = A · B. A chain of XORs over n bits is 1 when the number of 1s is odd, which is how a parity bit and a Hamming syndrome are computed. A ⊕ B is the “not equal” signal, so a bank of XORs OR-ed together compares two words. A ⊕ CTRL passes A when CTRL = 0 and inverts it when CTRL = 1, which is how a ripple-carry adder is turned into a subtractor. Binary converts to Gray code with Gᵢ = Bᵢ₊₁ ⊕ Bᵢ. LFSRs and CRCs are built from XOR taps. And because A ⊕ K ⊕ K = A, XOR is the operation behind the one-time pad and the three-XOR register swap. Standard part: 74HC86.

Gates people confuse with the XOR gate

XOR and OR

they differ on exactly one row, m₃ (11): OR gives 1, XOR gives 0. The English word “or” is usually exclusive; the gate called OR is inclusive. They differ on row m3 of the two-input table.

OR gate

XOR and XNOR

exact complement on every row. XOR is the inequality function and XNOR is the equality function. They differ on rows m0, m1, m2, m3 of the two-input table.

XNOR gate

XOR and NAND

XOR is 0,1,1,0 and NAND is 1,1,1,0, so they differ on exactly one row, m₀. Both are 1 when exactly one input is high. They differ on row m0 of the two-input table.

NAND gate

Common mistakes

  • Writing A ⊕ B = A + B because A and B are never both 1 in this circuit.True in that special case, but the gates differ in general. Write ⊕ if you mean exclusive.
  • Treating a 3-input XOR as “exactly one input high”.It is odd parity: 111 gives 1. “Exactly one” is the IEC =1 element, whose qualifying symbol for odd parity is 2k+1.
  • Expanding A ⊕ B into A′B + AB′ and calling that the simplified answer.Two literals beat four. The simplifier re-detects A′B + AB′ and returns A ⊕ B.

Start from a worked example

Worked examples

Sources

  1. G. Boole, An Investigation of the Laws of Thought, Walton and Maberly, London, 1854.
  2. C. E. Shannon, “A Symbolic Analysis of Relay and Switching Circuits,” Transactions of the AIEE, vol. 57, pp. 713–723, 1938.
  3. A. De Morgan, Formal Logic: or, The Calculus of Inference, Necessary and Probable, Taylor and Walton, London, 1847.
  4. ANSI/IEEE Std 91-1984 with IEEE Std 91a-1991, IEEE Standard Graphic Symbols for Logic Functions.
  5. IEC 60617-12:1997, Graphical symbols for diagrams — Part 12: Binary logic elements. (Paid standard; see the construction note beside every rectangular symbol.)
  6. F. Gray, “Pulse Code Communication,” U.S. Patent 2,632,058, filed 13 November 1947, granted 17 March 1953 — the reflected binary code built from XOR.