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
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.
Step 1 of 3 · X
Probability of each outcome after this step
- 001100%
First control to |1⟩.
The whole state moves from 000 to 001 — one certain outcome before, one certain outcome after, no superposition either side.
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.
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
Toffoli is the standard bridge between quantum circuits and classical reversible logic: it is exactly a reversible AND gate, and its decomposition cost (CNOTs and T gates) is a recurring resource-counting benchmark for fault-tolerant compilation.
Takes3 qubitsWhat joins here
Takes a 3-qubit register and states no assumption about what is on it. That is the whole condition: anything returning 3 qubits can feed it.
4 entries meet this end · 1 entry lines up on shape, composition unverified. Named below.
Returns3 qubitsWhat joins here
Returns a 3-qubit register a next stage can take. This is the end that joins.
2 entries meet this end · 14 entries line up on shape, composition unverified. Named below.
A unitary. The same register goes in and comes out, and this entry states no assumption about what is on it — which is what lets anything of the same width feed it. See all 29 →
The widths and types line up. What is not established is everything a width does not carry — the basis convention, the normalisation, the state each was written to start from — so this is not a claim that the two compose.
Definition
The Toffoli gate acts on the computational basis as
flipping the target bit exactly when both controls are . As an permutation matrix it is the identity everywhere except the swap.
Reversible classical logic
is the quantum realization of a reversible AND gate: with the target ancilla initialized to , computes the logical AND while remaining unitary and reversible, unlike a classical AND gate which discards information. Nielsen and Chuang show this makes alone universal for reversible classical computation, and (or plus any basis-changing single-qubit gate) universal for quantum computation.
Decomposition
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
for a total -count of 7 — the standard resource figure quoted when estimating the fault-tolerant cost of a circuit that uses Toffolis, since gates (not Clifford gates) dominate magic-state distillation cost.
Key identities
- is Hermitian and self-inverse: .
- 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- gates on more qubits () are built recursively from Toffolis and ancilla qubits, making the base case for the whole family used in Grover diffusion operators and reversible arithmetic circuits.
Takes3 qubitsWhat joins here
Takes a 3-qubit register and states no assumption about what is on it. That is the whole condition: anything returning 3 qubits can feed it.
4 entries meet this end · 1 entry lines up on shape, composition unverified. Named below.
Returns3 qubitsWhat joins here
Returns a 3-qubit register a next stage can take. This is the end that joins.
2 entries meet this end · 14 entries line up on shape, composition unverified. Named below.
A unitary. The same register goes in and comes out, and this entry states no assumption about what is on it — which is what lets anything of the same width feed it. See all 29 →
The widths and types line up. What is not established is everything a width does not carry — the basis convention, the normalisation, the state each was written to start from — so this is not a claim that the two compose.
- Qubits
- 3
- Depth
- 1 native / 6 CNOT decomposition
- T-count
- 7 (4 T, 3 T†)
- Truth table
- target ⊕= (c1 AND c2)
- Decomposition
- 6 CNOT + 2 H + 4 T + 3 T†
- Self-inverse
- CCX² = I
- Gate family
- Non-Clifford, classically universal
CCXon q[0], q[1], q[2]
Quantum vs classical
Classical baseline
Use a classical state-vector or matrix simulation at the same width, precision, and measurement objective.
Quantum claim
The quantum record demonstrates a state or operator behavior; it does not make classical simulation or communication costs disappear.
How to compare
Compare fidelity, samples, gate depth, noise, memory, and the cost of preparing and reading the state.
Nobody has reviewed this record for gaps yet.
OPENQASM 3.0;
include "stdgates.inc";
qubit[3] q;
x q[0];
x q[1];
ccx q[0], q[1], q[2];Related entries
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.