Lesson 04

Quantum gates

Short answer

A quantum gate is an operation that changes a qubit’s state. For a single qubit every gate is a rotation of the Bloch sphere: X, Y and Z turn it 180° around their own axes, Hadamard turns it 180° around the diagonal between X and Z, and S and T add 90° and 45° of phase.

Gates are matrices — and rotations

Mathematically, a gate on one qubit is a 2×2 matrix U that multiplies the state vector: |ψ'⟩ = U|ψ⟩. Not every matrix is allowed — it must be unitary, which means it keeps the total probability equal to 1 and can always be undone.

On the Bloch sphere that rule has a beautiful meaning: every single-qubit gate is a rotation of the sphere around some axis by some angle. Press any gate below; its rotation axis lights up in cyan while it acts.

All six gatesDrag to rotate
State|ψ⟩ = |0⟩θ = 0° · φ = 0°
P(0)
100%
P(1)
0%
|0⟩
your circuit appears here
Start: the qubit is in |0⟩

The arrow points at the north pole, so measuring now gives 0 every time. Press a gate to rotate it, or drag the sphere to look around.

The six gates at a glance

GateAxisAngle|0⟩ becomesChanges P(0)?
XX180°|1⟩yes
YY180°i|1⟩yes
ZZ180°|0⟩no
H(X + Z)/√2180°|+⟩yes
SZ90°|0⟩no
TZ45°|0⟩no

Pauli-X: the quantum NOT

X=(0110),X∣0⟩=∣1⟩,X∣1⟩=∣0⟩X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}, \qquad X|0\rangle = |1\rangle,\quad X|1\rangle = |0\rangle

X swaps the two amplitudes. On the sphere it is a half turn around the X axis, which carries the north pole to the south pole. It is the direct analogue of the classical NOT gate.

Pauli-Y

Y=(0−ii0)Y = \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}

A half turn around the Y axis. Like X it flips |0⟩ and |1⟩, but it also changes the phase. In fact Y = i·X·Z exactly.

Pauli-Z: the phase flip

Z=(100−1),Z∣+⟩=∣−⟩Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}, \qquad Z|+\rangle = |-\rangle

Z leaves |0⟩ alone and flips the sign of |1⟩. On the sphere it is a half turn around the vertical axis: the poles do not move and the probabilities never change, but a state on the equator swings to the opposite side.

The Hadamard gate

H=12(111−1),H∣0⟩=∣+⟩,H∣1⟩=∣−⟩H = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}, \qquad H|0\rangle = |+\rangle,\quad H|1\rangle = |-\rangle

The most used gate in quantum computing. It is a half turn around the diagonal axis halfway between X and Z, so it swaps the vertical axis with the X axis: poles go to the equator and back. Starting from |0⟩ it creates an equal superposition, which is why almost every algorithm begins with a layer of H gates.

The S gate

S=(100i),S∣+⟩=∣+i⟩S = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix}, \qquad S|+\rangle = |{+i}\rangle

A quarter turn around the vertical axis: it adds a 90° phase to |1⟩. Two S gates make a Z.

The T gate

T=(100eiπ/4)T = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{pmatrix}

An eighth of a turn around the vertical axis (45° of phase). Two T gates make an S. Together with H, the T gate can approximate any single-qubit rotation, which makes it essential for universal quantum computing.

Order matters

Rotations in 3D do not commute, so neither do gates. Starting from |0⟩:

  • H, then Z → |−⟩
  • Z, then H → |+⟩

Try both in the widget above (press Reset between them) and compare where the arrow ends up.

Every gate can be undone

Because gates are rotations, you can always rotate back. X, Y, Z and H are their own inverses — apply them twice and you are back where you started. S needs three more S gates (or one S†), and T needs seven more T gates (or one T†). Measurement is the only step in a quantum program that cannot be reversed.

Summary

  • A single-qubit gate is a unitary 2×2 matrix, and on the Bloch sphere it is a rotation.
  • X, Y, Z are half turns around the three axes; H is a half turn around the X–Z diagonal.
  • Z, S and T only change the phase — they spin the arrow around the vertical axis.
  • Gates do not commute: their order changes the result.

Frequently asked questions

Why are quantum gates reversible?

Quantum gates are unitary matrices: they preserve the total probability, and every unitary U has an inverse U† that undoes it. On the Bloch sphere this is obvious — every rotation can be undone by rotating back. Measurement is the one operation that is not reversible.

How many different single-qubit gates are there?

Infinitely many: any rotation of the Bloch sphere, by any angle around any axis, is a valid gate. X, Y, Z, H, S and T are simply the most common named ones. Rotations by an arbitrary angle are written Rx(θ), Ry(θ) and Rz(θ).

What is a universal gate set?

A small set of gates that can approximate any quantum operation to any accuracy when combined. A standard example is {H, T, CNOT}: H and T alone can approximate any single-qubit rotation, and adding the two-qubit CNOT gate makes the set universal for any number of qubits.

What is the difference between the Hadamard gate and a NOT gate?

The NOT gate (X) swaps |0⟩ and |1⟩ — a 180° turn around the X axis. The Hadamard gate turns 180° around the diagonal between X and Z, so it moves the poles onto the equator: |0⟩ becomes the superposition |+⟩. Both are their own inverse.