cs.thefarshad
medium

Quantum Gate Reference

A catalog of the workhorse gates — single-qubit rotations and the multi-qubit controlled gates — with their matrices and exactly what they do.

Every quantum circuit is built from a small set of reusable gates. This lesson is a reference: each single-qubit gate is a 2×22\times2 unitary matrix acting on the amplitude vector [αβ]\begin{bmatrix}\alpha\\\beta\end{bmatrix} of α∣0⟩+β∣1⟩\alpha|0\rangle + \beta|1\rangle, and each multi-qubit gate is a permutation (or sign change) on the computational basis states.

Pick a gate and an input below to see its matrix and the resulting amplitudes. Watch how YY, SS, and TT paint a phase onto an amplitude without changing its probability.

gate:
input:
H1/√2 ·
[
111−1
]
H |0⟩ =
(0.707) |0⟩ + (0.707) |1⟩
|0⟩
50.0%
|1⟩
50.0%

Hadamard: maps |0⟩→|+⟩ and |1⟩→|−⟩, creating equal superposition.

All amplitudes here are real, so the bars fully describe the state up to a sign.

Single-qubit gates

Pauli gates

The three Pauli gates are the fundamental single-qubit errors and also useful operations in their own right.

  • XX (NOT / bit flip): swaps the amplitudes of ∣0⟩|0\rangle and ∣1⟩|1\rangle.

X=[0110],X∣0⟩=∣1⟩,X∣1⟩=∣0⟩X = \begin{bmatrix}0&1\\1&0\end{bmatrix}, \qquad X|0\rangle = |1\rangle, \quad X|1\rangle = |0\rangle

  • YY (bit-and-phase flip): combines a bit flip with a phase, using imaginary entries.

Y=[0−ii0],Y∣0⟩=i∣1⟩,Y∣1⟩=−i∣0⟩Y = \begin{bmatrix}0&-i\\i&0\end{bmatrix}, \qquad Y|0\rangle = i|1\rangle, \quad Y|1\rangle = -i|0\rangle

  • ZZ (phase flip): leaves ∣0⟩|0\rangle alone and negates the ∣1⟩|1\rangle amplitude.

Z=[100−1],Z∣0⟩=∣0⟩,Z∣1⟩=−∣1⟩Z = \begin{bmatrix}1&0\\0&-1\end{bmatrix}, \qquad Z|0\rangle = |0\rangle, \quad Z|1\rangle = -|1\rangle

Hadamard

The Hadamard gate HH creates and destroys superposition. It maps the basis states to the even mixes ∣+⟩|+\rangle and ∣−⟩|-\rangle:

H=12[111−1],H∣0⟩=12(∣0⟩+∣1⟩)=∣+⟩,H∣1⟩=12(∣0⟩−∣1⟩)=∣−⟩H = \tfrac{1}{\sqrt2}\begin{bmatrix}1&1\\1&-1\end{bmatrix}, \qquad H|0\rangle = \tfrac{1}{\sqrt2}\big(|0\rangle + |1\rangle\big) = |+\rangle, \quad H|1\rangle = \tfrac{1}{\sqrt2}\big(|0\rangle - |1\rangle\big) = |-\rangle

Because H2=IH^2 = I, applying it twice returns the original state — the two branches interfere and recombine.

Phase gates: S and T

The SS and TT gates rotate the phase of the ∣1⟩|1\rangle amplitude. They do nothing visible to a single measurement, but they are essential for interference and for building arbitrary rotations.

S=[100i],T=[100eiπ/4]S = \begin{bmatrix}1&0\\0&i\end{bmatrix}, \qquad T = \begin{bmatrix}1&0\\0&e^{i\pi/4}\end{bmatrix}

Note the relationships S=T2S = T^2 and Z=S2=T4Z = S^2 = T^4: TT is a 45∘45^\circ phase, SS a 90∘90^\circ phase, and ZZ a 180∘180^\circ phase. The set {H,S}\{H, S\} generates the Clifford group; adding the non-Clifford TT gate makes the set universal for single-qubit operations.

A global phase like eiθe^{i\theta} multiplying the whole state is undetectable. Only a relative phase — a different phase on ∣1⟩|1\rangle than on ∣0⟩|0\rangle — changes physics, and it does so by steering later interference.

Multi-qubit gates

Multi-qubit gates act on 2n2^n basis states. We order two-qubit states as ∣00⟩,∣01⟩,∣10⟩,∣11⟩|00\rangle, |01\rangle, |10\rangle, |11\rangle, with the left bit as the control where relevant.

CNOT (controlled-NOT)

CNOT\mathrm{CNOT} flips the target qubit when the control is ∣1⟩|1\rangle, and does nothing when the control is ∣0⟩|0\rangle:

CNOT=[1000010000010010]\mathrm{CNOT} = \begin{bmatrix}1&0&0&0\\0&1&0&0\\0&0&0&1\\0&0&1&0\end{bmatrix}

inputoutput
$00\rangle$
$01\rangle$
$10\rangle$
$11\rangle$

It is the entangling gate behind the Bell state: CNOT (H⊗I)∣00⟩=12(∣00⟩+∣11⟩)\mathrm{CNOT}\,(H\otimes I)|00\rangle = \tfrac{1}{\sqrt2}(|00\rangle + |11\rangle).

CZ (controlled-Z)

CZ\mathrm{CZ} applies a ZZ to the target when the control is ∣1⟩|1\rangle — in practice it just flips the sign of ∣11⟩|11\rangle. It is symmetric: control and target are interchangeable.

CZ=[100001000010000−1]\mathrm{CZ} = \begin{bmatrix}1&0&0&0\\0&1&0&0\\0&0&1&0\\0&0&0&-1\end{bmatrix}

inputoutput
$00\rangle$
$01\rangle$
$10\rangle$
$11\rangle$

Conjugating with Hadamards on the target turns one into the other: CNOT=(I⊗H) CZ (I⊗H)\mathrm{CNOT} = (I\otimes H)\,\mathrm{CZ}\,(I\otimes H).

SWAP

SWAP\mathrm{SWAP} exchanges the states of the two qubits, leaving the matching basis states ∣00⟩|00\rangle and ∣11⟩|11\rangle fixed:

SWAP=[1000001001000001]\mathrm{SWAP} = \begin{bmatrix}1&0&0&0\\0&0&1&0\\0&1&0&0\\0&0&0&1\end{bmatrix}

inputoutput
$00\rangle$
$01\rangle$
$10\rangle$
$11\rangle$

A SWAP\mathrm{SWAP} decomposes into three CNOTs in alternating directions.

Toffoli (CCNOT)

The Toffoli gate is a doubly-controlled NOT on three qubits (8×88\times8): it flips the target only when both controls are ∣1⟩|1\rangle. Every basis state is unchanged except the last two, which are swapped:

inputoutput
$110\rangle$
$111\rangle$
all othersunchanged

CCNOT ∣a,b,c⟩=∣a, b, c⊕(a∧b)⟩\mathrm{CCNOT}\,|a, b, c\rangle = |a,\, b,\, c \oplus (a \wedge b)\rangle

Toffoli is universal for classical reversible computation — it can build AND, NAND, and fan-out — so it bridges classical logic into the reversible quantum world.

Takeaways

  • Single-qubit gates are 2×22\times2 unitaries: XX flips bits, ZZ flips phase, YY does both, and HH creates superposition.
  • SS and TT add 90∘90^\circ and 45∘45^\circ phases to ∣1⟩|1\rangle; with {H,S,T}\{H, S, T\} you can approximate any single-qubit gate, and TT is the non-Clifford piece.
  • A relative phase is invisible to one measurement but governs interference; a global phase is never observable.
  • CNOT and CZ are the entangling two-qubit gates (related by Hadamards on the target), SWAP exchanges two qubits, and Toffoli (CCNOT) is universal for reversible classical logic.

References