← Atlas

Gates · Multi-controlled gate

Toffoli (CCX) gate

The three-qubit doubly-controlled NOT gate that implements reversible classical AND/NAND logic and is universal for classical reversible computation.

Exact & formalUpdated

View frozen graph

A small worked example, computed in your browser. It is not a result from this record's papers.

The Toffoli gate computes an AND

Three qubits, with both controls set to |1⟩ — the one case out of four in which the target flips.

q0q1q2Step 1 of 3 · XXStep 2 of 3 · XXStep 3 of 3 · CCXCCX

Step 1 of 3 · X

Probability of each outcome after this step

  • 001100%
  1. First control to |1⟩.

    The whole state moves from 000 to 001 — one certain outcome before, one certain outcome after, no superposition either side.

  2. Second control to |1⟩, so both are now set.

    The whole state moves from 001 to 011 — one certain outcome before, one certain outcome after, no superposition either side.

  3. Flips the target only because both controls are 1 — the target ends up holding their AND. This is why Toffoli is universal for classical reversible computation: anything a classical circuit can compute, a circuit of these can compute reversibly.

    The whole state moves from 011 to 111 — one certain outcome before, one certain outcome after, no superposition either side.

Readout The register reads 111. Change either control to 0 and the target stays 0 — the gate is an AND, written so that it can be undone by applying it again.

Open in Studio
  • Steps1
  • Wires3
  • Qubits3
  • Depth1 native / 6 CNOT decomposition
  • T-count7 (4 T, 3 T†)
  • Papers2

Definition

The Toffoli gate acts on the computational basis as

CCX∣c1,c2,t⟩=∣c1,c2, t⊕(c1∧c2)⟩\mathrm{CCX}|c_1,c_2,t\rangle = |c_1,c_2,\, t \oplus (c_1 \wedge c_2)\rangle

flipping the target bit exactly when both controls are 11. As an 8×88\times 8 permutation matrix it is the identity everywhere except the ∣110⟩↔∣111⟩|110\rangle \leftrightarrow |111\rangle swap.

Reversible classical logic

CCX\mathrm{CCX} is the quantum realization of a reversible AND gate: with the target ancilla initialized to ∣0⟩|0\rangle, CCX∣c1,c2,0⟩=∣c1,c2, c1∧c2⟩\mathrm{CCX}|c_1,c_2,0\rangle = |c_1,c_2,\,c_1\wedge c_2\rangle computes the logical AND while remaining unitary and reversible, unlike a classical AND gate which discards information. Nielsen and Chuang show this makes {CCX}\{\mathrm{CCX}\} alone universal for reversible classical computation, and {CCX,H}\{\mathrm{CCX}, H\} (or {CCX}\{\mathrm{CCX}\} plus any basis-changing single-qubit gate) universal for quantum computation.

Decomposition

CCX\mathrm{CCX} has no native two-qubit hardware analogue and is not itself Clifford. The standard circuit (Barenco et al. 1995; also Nielsen & Chuang Fig. 4.9) decomposes it into

6 CNOT gates  +  2 H  +  4 T  +  3 T†6\ \text{CNOT gates} \;+\; 2\ H \;+\; 4\ T \;+\; 3\ T^\dagger

for a total TT-count of 7 — the standard resource figure quoted when estimating the fault-tolerant cost of a circuit that uses Toffolis, since TT gates (not Clifford gates) dominate magic-state distillation cost.

Key identities

  • CCX\mathrm{CCX} is Hermitian and self-inverse: CCX2=I\mathrm{CCX}^2 = I.
  • CCX\mathrm{CCX} is symmetric in its two control qubits but not in the target: swapping the two controls leaves the gate unchanged, swapping a control with the target does not.
  • Multi-controlled-XX gates on more qubits (CnXC^nX) are built recursively from Toffolis and ancilla qubits, making CCX\mathrm{CCX} the base case for the whole family used in Grover diffusion operators and reversible arithmetic circuits.

References

  • Elementary gates for quantum computation

    Adriano Barenco, Charles H. Bennett, Richard Cleve, David P. DiVincenzo, Norman Margolus, Peter Shor, Tycho Sleator, John A. Smolin, Harald Weinfurter · 1995

    Shows that single-qubit U(2) gates plus CNOT are universal and gives explicit decompositions for controlled-U, Toffoli, and Fredkin gates.

  • Quantum Computation and Quantum Information: 10th Anniversary Edition

    Michael A. Nielsen and Isaac L. Chuang · 2010

    Standard reference for single- and multi-qubit gate matrices, Euler-angle decomposition, and universal gate sets.

Exact & formal
  • Basis-state truth table
  • Unitary / matrix equivalence
  • Peer-reviewed paper
  • Textbook / standard citation
Method
Apply CCX to all eight computational-basis inputs and confirm the target flips only for the |11⟩ control pair.
Result
Pass · CCX|1,1,t⟩ = |1,1,1-t⟩ and CCX leaves all other seven basis states unchanged.
OpenQASM 3 standard gate set ↗
Kind
curated reference
Reviewed by
Leona Quantum curation pass
License
CC BY 4.0-compatible reference metadata
toffolireversible logicthree qubituniversal

Atlas stars stay in the public catalog. Saving this entry to your workspace starts an unstarred private copy.