XOR gate

The gate that fires when exactly one of its inputs is on. A plain-English guide to logic gates from TorchAnvil.

An XOR gate — "exclusive or" — has two inputs and one output. The output is high when exactly one input is high. If both inputs match (both off, or both on), the output is zero.

How to read it

Think of XOR as the answer to "are these two inputs different?" If A and B disagree, XOR fires. If they agree, it stays silent. It's the difference detector of digital logic.

A B A ⊕ B
0 0 0
0 1 1
1 0 1
1 1 0

The ⊕ symbol is a plus inside a circle — addition, modulo 2. That's the most useful way to think about XOR: it's binary addition where you throw the carry away. 1 ⊕ 1 = 0 because 1 + 1 = 2, and 2 mod 2 is 0.

Why it matters

XOR has a strange, lovely set of superpowers that pop up everywhere:

A worked example: the half adder

Add two single bits, A and B. The result needs two outputs, because 1 + 1 is 10 in binary and won't fit in one:

A B Sum Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1

Look at the Sum column: that's XOR exactly. Look at Carry: that's AND exactly.

Two gates and you have a half adder — a circuit that genuinely does arithmetic. Chain two of them plus an OR and you get a full adder that accepts a carry in; chain four of those and you can add any two numbers from 0 to 15. That is the entire path from one XOR gate to a working calculator, and there is nothing else hiding in it.

The self-inverse trick

XOR is its own inverse, which is unusual and extremely useful:

(X ⊕ K) ⊕ K = X

Apply a value twice and you're back where you started. This one identity underpins a surprising amount of computing:

How it differs from OR

They agree on three rows and differ on the last one:

A B OR XOR
0 0 0 0
0 1 1 1
1 0 1 1
1 1 1 0

English is unhelpful here. "Tea or coffee?" means one or the other — XOR. "Bring a coat or an umbrella" allows both — OR. Since everyday speech uses "or" for both meanings, your intuition can't be trusted; check the both-on row deliberately every time.

In redstone

XOR is the first gate in Minecraft that actually takes some thought — there's no one-block version. The usual build uses a pair of torches that cancel each other out when both inputs match, lighting only when the inputs disagree.

Expressed in gates, the common redstone XOR is:

which is why it needs more components than anything else on this list. The XOR redstone pattern has the canonical layout with a footprint and a bill of materials.

Building it from other gates

Gotchas

Try it

The demo on the right is one XOR between two levers, feeding a lamp. Flip one lever and the lamp lights. Flip the other one also on, and the lamp goes dark — exactly one is no longer true.

Then add an AND across the same two levers and a second lamp. You've built a half adder: the first lamp is the sum, the second is the carry.

Frequently asked questions

What is an XOR gate?
An XOR gate, or exclusive or, outputs high when exactly one of its two inputs is high. If both inputs match — both off or both on — the output is low, which makes it a difference detector.
What is the difference between XOR and OR?
Only the both-inputs-on row. OR outputs 1 there and XOR outputs 0. OR means "at least one"; XOR means "exactly one".
Why is XOR used in a half adder?
Because the sum of two bits is their XOR. Adding 1 and 1 gives binary 10, so the sum bit is 0 and the carry is 1 — which matches XOR for the sum and AND for the carry exactly.
Why is XOR used in encryption?
Because it is its own inverse. XOR-ing data with a key encrypts it, and XOR-ing the result with the same key returns the original, so one operation serves both directions.
How do you build an XOR gate in Minecraft redstone?
There is no single-block XOR. The standard build combines the inputs so that a pair of torches cancel when the inputs match, which in gate terms is (A OR B) AND NOT(A AND B) — at least one, but not both.