XOR Gate: Truth Table, Boolean Expression and Examples
Learn the XOR gate truth table, Boolean expression and difference from OR. Try a controllable inverter and see how XOR supports addition and parity.
TL;DR: The XOR (Exclusive OR) gate outputs 1 only when its inputs differ. Boolean expression . XOR is binary addition modulo 2, the sum bit of a half adder, the basis of parity reduction, a controllable inverter for arithmetic circuits, and an operation used in many cryptographic constructions.
Test the XOR gate in Digital Logic Lab: toggle both inputs through 00, 01, 10 and 11, then compare the output with the truth table below. For the component’s controls, read the XOR gate reference.
The XOR gate detects two-input inequality: it outputs HIGH only when its inputs disagree. XOR also represents addition modulo 2, which is why it appears within parity equations and many arithmetic and cryptographic constructions. Those systems require additional logic and constraints; XOR alone is not an adder, an error-correcting code, or a cipher.
What is an XOR Gate? The Logic of Difference
At its core, an XOR gate is a digital logic gate that produces a HIGH output (1) only when its inputs are dissimilar. If the inputs are the same—both HIGH or both LOW—the output is LOW (0). This “exclusive” nature is what distinguishes it from a standard OR gate, which would output HIGH if one or both inputs were HIGH.
Think of it as a strict “one or the other, but not both” rule. For two inputs, this is exactly the Boolean inequality function.

Technical Specification: The Truth Table
The behavior of a 2-input XOR gate is specified by its truth table. Let’s denote the inputs as and , and the output as .
| Input A | Input B | Output Y | Description |
|---|---|---|---|
| 0 | 0 | 0 | Inputs are the same (LOW) |
| 0 | 1 | 1 | Inputs are different |
| 1 | 0 | 1 | Inputs are different |
| 1 | 1 | 0 | Inputs are the same (HIGH) |
The pattern is unmistakable: the output is 1 if and only if the inputs are not equal. This makes a 2-input XOR a direct difference detector.
The Boolean Expression
In Boolean algebra, the XOR operation is represented by the symbol . The equation for the output is:
This is the shorthand we use in high-level design. However, to understand how to build an XOR gate from more basic components like AND, OR, and NOT, we can expand this expression into its Sum-of-Products (SOP) form. This form directly translates from the truth table rows where the output is 1:
This equation reads: “The output is HIGH if (NOT A is HIGH AND B is HIGH) OR (A is HIGH AND NOT B is HIGH).” If you were to build this using discrete gates on digisim.io, you’d need two NOT gates, two AND gates, and one OR gate. The XOR symbol expresses this function as one logical block; physical implementation cost depends on the target library or device technology.
Common Pitfall: The Multi-Input Misconception
The 2-input XOR is a “difference detector.” When a third input is added, it is tempting — and wrong — to assume the gate outputs 1 only when exactly one of the three inputs is 1.
For three or more inputs, the standard associative XOR reduction has a different interpretation.
A multi-input XOR gate functions as an odd-parity detector. It outputs 1 if there is an odd number of HIGH inputs. Let’s look at the 3-input truth table to see why:
| A | B | C | Count of 1s | |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 (Even) |
| 0 | 0 | 1 | 1 | 1 (Odd) |
| 0 | 1 | 0 | 1 | 1 (Odd) |
| 0 | 1 | 1 | 0 | 2 (Even) |
| 1 | 0 | 0 | 1 | 1 (Odd) |
| 1 | 0 | 1 | 0 | 2 (Even) |
| 1 | 1 | 0 | 0 | 2 (Even) |
| 1 | 1 | 1 | 1 | 3 (Odd) |
Why does this happen? It’s due to the associative property of XOR: . The circuit essentially cascades the XOR logic. The first gate checks if A and B are different. The second gate then checks if that result is different from C.
This behavior supports parity checks. If a single received bit changes, an XOR reduction changes polarity and the parity check fails. More generally, simple parity detects every odd number of bit changes but misses every even number, so passing parity is not proof that the data is correct.
Hands-On: The Controllable Inverter
One practical use of XOR is a controllable inverter. A conventional adder/subtractor can XOR each bit of one operand with a subtract control and apply that same control as carry-in, thereby forming the two’s complement used for subtraction. This is a common teaching and implementation pattern, not a requirement that every ALU contain visible XOR gates.
Imagine you have two inputs: Data and Control.
- If Control is 0: . The signal passes through unchanged.
- If Control is 1: . The signal is inverted.
Toggling the control changes the same XOR cell between pass-through and inversion. A conventional adder/subtractor uses this relationship together with carry-in; other ALU implementations may realize subtraction differently.
Building it on digisim.io
- Open the digisim.io editor.
- Place an XOR gate in the center.
- Connect two INPUT_SWITCH components to the inputs. Label one “Data” and the other “Control” using the TEXT tool.
- Connect an OUTPUT_LIGHT to the output.
- Toggle the “Control” switch and watch how the “Data” switch’s influence on the light changes.
To see this in a more complex context, check out the XOR Difference Detector template:

Verifying Behavior with the OSCILLOSCOPE
When you’re working with high-speed circuits, the “instant” change of a gate is an illusion. Every gate has a propagation delay (). In digisim.io, you can visualize this timing using the OSCILLOSCOPE.
Connect the inputs and output to an OSCILLOSCOPE_8CH to inspect transitions represented by DigiSim’s event model. A waveform can reveal a modeled hazard only when the network, input transition, delay semantics, and display resolution produce one. It cannot prove a physical implementation glitch-free or reproduce analog pulse amplitude, noise, or process-voltage-temperature variation. Use static timing and the target technology’s characterization for hardware sign-off.
Application 1: Binary arithmetic
In the standard half-adder decomposition, XOR supplies Sum and AND supplies Carry. When you add two binary digits, the “Sum” is calculated using XOR, while the “Carry” is calculated using an AND gate.
Consider in binary.
- The Sum () is 0.
- The Carry () is 1.
- Result: (which is 2 in decimal).
The XOR function is a concise way to express a sum bit. Equivalent arithmetic can be synthesized from NAND, NOR, compound cells, or programmable logic, so a software workload does not imply a count of standalone XOR operations in a particular processor.

Explore the Half-Adder Template
Application 2: Cryptographic constructions
XOR is widely used in symmetric cryptography because it is inexpensive and self-inverse.
If you have a message () and a secret key (), you can create a ciphertext () by XORing them together:
To get the original message back, you simply XOR the ciphertext with the same key:
This algebra underlies the one-time pad, which provides perfect secrecy only when the key is uniformly random, at least as long as the message, kept secret, and never reused. AES also uses XOR for the AddRoundKey transformation, but its security comes from the complete standardized construction, key size, implementation, and mode of use—not from XOR alone.
Common Mistakes to Avoid
When building XOR circuits on digisim.io, keep these “Pro Tips” in mind:
- Floating Inputs: Never leave an XOR input unconnected. In a real circuit, a floating input can pick up electrical noise and cause the gate to oscillate. In digisim.io, use a CONSTANT_ZERO if you need to tie an unused input to a known state.
- Logic Levels: Remember that XOR is a logic gate, not a power switch. It can signal a difference, but it shouldn’t be used to drive high-current components directly without a BUFFER or a transistor model.
- The OR confusion: For two inputs, OR and XOR differ only at
11. Use XOR for bitwise inequality; use an OR reduction to report whether any per-bit mismatch is present in a word.
Master the Logic of Difference
The 2-input inequality rule extends to associative modulo-2 reduction. That operation is useful in arithmetic, parity checks, and cryptographic designs when combined with the rest of each construction. The next post in this series, The XNOR Gate, is the equality-detector counterpart, and XOR vs. XNOR: The Critical Difference in Error Detection compares them head-to-head.
Open the XOR component reference to verify the truth table, then build the controllable inverter from this post directly in the simulator.
Related Lessons for Further Study
- The XNOR Gate — the complement gate.
- The Half Adder and Half Adder vs. Full Adder — XOR as the sum bit.
- Visualizing Logic: Karnaugh Maps — recognizing parity and equality patterns during simplification.
Continue learning
NAND truth table · XNOR truth table · Digital logic simulator and learning paths



