Gates & circuits

Toffoli gate (CCNOT)

Think of the Toffoli gate as a careful light switch with a safety interlock. It watches two control wires and acts on a third, the target. The rule is simple: flip the target only when both controls are 1; if either control is 0, leave everything exactly as it was. Because it touches three bits at once, you will sometimes hear it called the controlled-controlled-NOT, or CCNOT.

What makes it special is that it is reversible: run it a second time and you are back where you started, because no information is ever thrown away. Ordinary classical logic is not like this. An AND gate, for example, takes two inputs down to one output, and you cannot recover the inputs from the answer. The Toffoli gate sidesteps that loss by keeping enough wires around, and it can imitate AND, NAND, and other classical operations while staying reversible. That is exactly what a quantum computer needs, since every quantum gate must be reversible (unitary).

So the Toffoli gate is the bridge between classical arithmetic and quantum circuits. When a quantum algorithm has to add numbers, compare them, or compute some ordinary function on the way to the part where quantum interference does the real work, Toffoli gates do that bookkeeping. They also appear constantly in fault-tolerant designs, where reliable logic has to be built up from simpler, error-corrected pieces.

(a, b, c) -> (a, b, c XOR (a AND b))

The two controls a and b pass through unchanged; the target c is flipped (XOR 1) only when both a and b are 1.

The Toffoli gate does not itself give a speedup; it is reversible classical logic that lets quantum circuits carry out ordinary computation as a building block, and on its own it is not enough for a universal quantum computer (you also need a gate like H that creates superposition).

Also called
CCNOTcontrolled-controlled-NOTCCX