Overview
An XOR gate (Exclusive OR gate) outputs HIGH only when its inputs are different from each other. When both inputs are LOW or both are HIGH, the output is LOW. The "exclusive" in XOR emphasises that unlike ordinary OR (which includes the both-true case), XOR excludes the case where all inputs are simultaneously HIGH.
This simple "difference detector" behaviour gives XOR a remarkable range of applications: it is the key circuit in binary adders (computing the sum bit), parity generators (checking for transmission errors), cryptographic systems (one-time pad encryption), and programmable logic devices. XOR is unusual because it is both self-inverse (A ⊕ A = 0, A ⊕ 0 = A) and associative, making it ideal for reversible operations like symmetric encryption.
The symbol for XOR is ⊕ (a circle with a plus sign). The boolean expression is Y = A ⊕ B = A'B + AB'. In circuit diagrams, the XOR gate resembles an OR gate but with an additional curved line across the input side.
How It Works
XOR truth table for 2 inputs: (0,0) → 0: inputs are the same (0,1) → 1: inputs are different (1,0) → 1: inputs are different (1,1) → 0: inputs are the same
Why XOR is perfect for binary addition: In binary arithmetic, 0+0=0, 0+1=1, 1+0=1, 1+1=10₂. The sum bit (LSB of the result) is exactly the XOR of the two inputs. This is why half adders use an XOR gate for the sum output.
XOR self-inverse property: A ⊕ B ⊕ B = A. XORing any bit stream with a key and then XORing again with the same key perfectly recovers the original — this property underpins one-time pad encryption and many stream ciphers.
CMOS XOR implementation typically uses 8–10 transistors in a transmission-gate topology, making it more complex than AND or OR (4–6 transistors each).
Real-World Applications
The sum bit in every binary adder is computed with XOR: Sum = A ⊕ B for a half adder, Sum = A ⊕ B ⊕ Cin for a full adder.
XORing all bits of a data word generates a parity bit. Re-XORing at the receiver detects whether an odd number of bit errors occurred in transmission.
Cyclic Redundancy Checks use XOR division (polynomial division in GF(2)) to generate check values that detect burst errors in data storage and communication.
XORing plaintext with a random key of equal length produces ciphertext. The recipient XORs with the same key to decrypt. This is information-theoretically secure if the key is truly random and used only once.
RAID 5 and RAID 6 disk arrays use XOR to compute parity stripes that can reconstruct data if one (or two, in RAID 6) disks fail.
Try It in the Interactive Simulator
Build What Is an XOR Gate? circuits in real time — drag gates, connect wires, toggle inputs, and see outputs update instantly.
Frequently Asked Questions
- What does XOR mean?
XOR stands for "Exclusive OR." It outputs 1 when exactly one input is 1 (inputs are different). It outputs 0 when both inputs are the same. It is the "either/or, but not both" gate.
- How is XOR different from OR?
OR outputs 1 when any input is 1, including when all are 1. XOR outputs 1 only when an odd number of inputs are 1. For 2 inputs: OR(1,1)=1 but XOR(1,1)=0.
- Why is XOR used in encryption?
XOR is its own inverse: A ⊕ key ⊕ key = A. So the same XOR operation both encrypts and decrypts. Combined with a random key, this produces the perfectly secure one-time pad cipher.
- What is the boolean expression for XOR?
Y = A ⊕ B = A'B + AB'. XOR can also be written as (A+B)(A'+B') or (A+B)(AB)'.
- Can XOR detect all errors?
XOR parity can only detect an odd number of bit errors (1, 3, 5...). An even number of simultaneous errors cancel out and go undetected. For stronger error detection, CRC or Hamming codes are used.