A two-input XOR gate outputs 1 when its inputs differ and 0 when they match. Its expression is Y=A⊕B, equivalent to (NOT A AND B) OR (A AND NOT B). XOR is useful for sum bits, parity and detecting binary differences.
Reviewed 12 November 2026 · Binary examples checked with executable tests.
On this page
What is the XOR truth table?
| A | B | XOR | XNOR |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
There are two rows with output 1: 01 and 10. The input pair 11 gives 0, which distinguishes XOR from OR. XNOR is the complement and is high for 00 and 11.
How is the Boolean expression derived?
Write one product term for each row that makes the output high. The 01 row contributes A′B, while 10 contributes AB′. Combining them gives:
Y = A'B + AB' = A XOR B
A XOR 0 = A
A XOR 1 = NOT A
A XOR A = 0These identities make XOR a selectable inverter: a control of 0 passes the data and a control of 1 inverts it. They also help check a circuit without drawing every internal transistor.
How can four NAND gates make XOR?
Label the shared first result before following the two branches:
n1 = NAND(A, B)
n2 = NAND(A, n1)
n3 = NAND(B, n1)
Y = NAND(n2, n3)The accompanying binary tests compare this network against A XOR B for all four inputs. A matching truth table proves the ideal binary function; it does not imply equal propagation delay, area or power to a dedicated XOR cell.
Why does an adder use XOR?
A half adder calculates Sum=A XOR B and Carry=A AND B. For 1+1, Sum=0 and Carry=1: the two output bits represent binary 10, or decimal 2. XOR alone does not perform the complete addition because it omits the carry.
A full adder introduces a carry input, giving Sum=A XOR B XOR Cin. Its carry output is a separate function; see the two-half-adder construction.
Does multi-input XOR mean exactly one input is 1?
No. A cascade of XOR operations is high when an odd number of its binary inputs are high. With three inputs, 111 produces 1 because there are three ones. This differs from a circuit that asserts only when exactly one of three inputs is high.
| A | B | C | A XOR B XOR C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
An XOR reduction can create a parity bit, but parity is not a full error-correcting code. Odd numbers of bit changes affect parity; some even-numbered changes leave it unchanged. Specify the protected data and parity convention before using it as an error check.
Common questions
Is XOR a universal gate by itself?
No. Networks made solely from XOR and constants produce affine Boolean functions. They cannot express every Boolean function; NAND or NOR alone can.
Is XOR the same as addition?
XOR gives addition modulo 2 for one-bit values, which is the sum bit without carry. Ordinary binary addition also requires carry generation and propagation.
Can XOR compare two words?
Bitwise XOR marks differing bit positions. A reduction OR of those differences indicates that at least one bit differs; a zero result indicates equality for valid binary inputs.
References and checks
Download the functional tests and model source. These check stated binary functions; they do not establish analog timing, physical implementation, fault coverage or board behavior.