Toffoli gate (CCX)

Flips the target only when both controls are 1: a reversible AND.

Reversible logic · 3 qubits · reviewed November 2026

Matrix

8×8 identity, except that the |110⟩ and |111⟩ rows are swapped

What it does

|110⟩→|111⟩
|111⟩→|110⟩
any other basis state→unchanged

In plain words

The Toffoli gate shows that classical logic fits inside quantum computing. It needs six CNOTs and several T gates in its standard decomposition, so it is expensive on early hardware.

Identities

  • CCX·CCX = I
  • With the target at 0, the output is control1 AND control2

Where it is used

  • Reversible arithmetic
  • Error-correction syndrome logic
  • Grover oracles on more qubits

Code

# Qiskit
qc.ccx(0, 1, 2)

// OpenQASM 2.0
ccx q[0],q[1],q[2];

Qiskit prints qubit 0 on the right of a bitstring. The builder prints it on the left.

See it in an example

Related gates

Questions

Is the Toffoli gate universal?

For classical reversible computation yes. With the Hadamard it is universal for quantum computation.

Try the CCX gate in the Circuit Builder →