Sign in
← Atlas
Exact & formalGatesMulti-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.

toffolireversible logicthree qubituniversal

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

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.

Circuit & simulation
|110⟩ → |111⟩100%
all other 7 inputs unchanged100%
What this takes and returns
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.

3 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 →

Shapes fit before this, composition unverified 1

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.

How it works

Definition

The Toffoli gate acts on the computational basis as

CCXc1,c2,t=c1,c2,t(c1c2)\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 110111|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, CCXc1,c2,0=c1,c2,c1c2\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 T6\ \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.
Implementation
Native
toffoli-ccx.qasm
OPENQASM 3.0;
include "stdgates.inc";
qubit[3] q;
x q[0];
x q[1];
ccx 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.

Declared gaps

Nobody has reviewed this record for gaps yet.

Literature & references
Elementary gates for quantum computation1995 · Adriano Barenco, Charles H. Bennett, Richard Cleve, David P. DiVincenzo, Norman Margolus, Peter Shor, Tycho Sleator, John A. Smolin, Harald Weinfurter

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

arxiv.org/abs/quant-ph/9503016
Quantum Computation and Quantum Information: 10th Anniversary Edition2010 · Michael A. Nielsen and Isaac L. Chuang

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

doi.org/10.1017/cbo9780511976667