Compact Comparator XOR Gate

An XOR (exclusive OR) gate outputs a redstone signal only when its two inputs are in different states (one ON and one OFF). It is ideal for controlling a single door, light, or piston contraption from two separate levers so flipping either switch always toggles the output. This compact comparator design replaces bulky traditional torch gates with just two comparators and a handful of redstone dust.

Logic GatesBeginnerJava & Bedrock
Compact Comparator XOR Gate video tutorial

Video: Very Easy & Simple Compact Comparator XOR Gate (Minecraft Redstone Tutorial) by Drackiseries - Minecraft YouTuber

How to build it

  1. Place the Two Input Levers

    Place two levers on the ground with a one-block gap between them. These will act as Input A and Input B for your logic gate.

  2. Add the Comparators in Subtract Mode

    Directly in front of each lever, place a redstone comparator facing forward away from the levers. Right-click (interact with) both comparators so their front torches light up, putting them into subtract mode.

  3. Wire the Rear and Side Inputs

    Place redstone dust behind and between the comparators so that each lever connects into the back of its own comparator as well as the side of the opposite comparator.

  4. Connect the Outputs Together

    Run redstone dust in front of both comparators and merge the lines into a single output line. Place a redstone lamp (or your target mechanism) at the end of this output line.

  5. Test the XOR Gate

    Flip one lever ON while leaving the other OFF—the lamp will light up. Flip both levers ON or both OFF and the lamp will turn off.

How it works

This circuit relies on how a redstone comparator in subtract mode calculates signal strength. In subtract mode, a comparator takes its rear input signal strength and subtracts the highest side input signal strength: Output = max(0, Rear - max(Left, Right)).

  • Both inputs OFF (0, 0): Neither comparator receives power at the rear input, so both output 0 and the lamp stays off.
  • One input ON (1, 0 or 0, 1): The active lever sends a full signal into the rear of one comparator and into the side of the other. The comparator receiving only a side input outputs 0, while the comparator receiving only a rear input has nothing subtracted from it (15 - 0 = 15) and powers the output line.
  • Both inputs ON (1, 1): Both comparators receive equal signal strength at their rear and side inputs. Because the rear and side signals are equal, they cancel each other out (15 - 15 = 0), turning the output completely off.

Tips & variations

  • Convert to an XNOR Gate: To invert the behavior so the output is ON only when both levers match, place a solid block at the end of the output dust with a redstone torch on the far side (an inverter).
  • Common Mistake: Forgetting to toggle both comparators into subtract mode (front torch lit). If left in compare mode, the gate may still cancel at equal strengths, but subtract mode guarantees clean subtraction across varying input line lengths.
  • Edition Note: Built and demonstrated in Minecraft 1.18.2 Java Edition, though comparator subtraction works identically in Bedrock Edition.

Frequently asked questions

What is an XOR gate used for in Minecraft?
An XOR gate lets you control one device, such as a piston door or lighting system, from two different levers (like inside and outside a room) so flipping either lever always toggles the door.
Why won't my comparator XOR gate turn off when both levers are on?
Make sure both comparators are set to subtract mode (the single front torch is glowing) and that the dust connecting each input reaches the side of the opposite comparator at the same signal strength as the rear.
How do I turn this XOR gate into an XNOR gate?
Place a solid block at the output redstone line and attach a redstone torch to it. This inverts the signal so the output turns on only when both inputs are identical.

Components used

More xor gate