A classical computer is built from logic gates such as AND, OR and NOT. A quantum computer, in the circuit model, is built from quantum gates: operations that transform the state of one or a few qubits. A handful of standard gates, and the habit of tracing their effect on amplitudes, is enough to read most textbook quantum circuits.
Gates are unitary, and therefore reversible
A qubit's state is a vector of complex amplitudes, for example α|0⟩ + β|1⟩, with |α|² + |β|² = 1. A gate is represented by a matrix U that multiplies this vector. For the result to be a valid state for every possible input, U must preserve the total probability. Matrices with that property are called unitary, which means U†U = I, where U† is the conjugate transpose and I the identity.
Every unitary matrix has an inverse, namely U†. So every quantum gate is reversible: in principle you can undo it exactly. Classical gates like AND, by contrast, erase information: from an output of 0 you cannot tell which inputs produced it.
Measurement appears in circuit diagrams but is not a gate in this sense. It is neither unitary nor reversible: it gives a random outcome by the Born rule and replaces the state with the matching basis state. Both |+⟩ and |−⟩ can yield 0 and leave |0⟩ behind, so the original cannot be reconstructed. Circuits are therefore usually arranged so measurement comes last, after interference has concentrated probability on useful answers.
Two notational conventions used below: a single-qubit gate is a 2×2 matrix acting on the column vector (α, β), and gates in a circuit are applied left to right in time, which corresponds to multiplying matrices from right to left.
Single-qubit gates: X, Y, Z, H, S and T
The three Pauli gates are the most basic single-qubit operations.
- X = [[0, 1], [1, 0]]. It swaps the amplitudes: X(α|0⟩ + β|1⟩) = β|0⟩ + α|1⟩. On basis states it acts like a classical NOT, so it is often called the bit-flip gate.
- Z = [[1, 0], [0, −1]]. It leaves |0⟩ alone and multiplies |1⟩ by −1: Z(α|0⟩ + β|1⟩) = α|0⟩ − β|1⟩. This is a phase flip. It does not change the probabilities of 0 and 1, but it changes how the state interferes later.
- Y = [[0, −i], [i, 0]]. It combines both: Y = iXZ, so it flips the bit and the phase, up to an overall factor.
On the Bloch sphere, each Pauli gate is a rotation by 180 degrees about the corresponding axis. You can watch these rotations in the Bloch sphere module of the interactive lab.
- H (Hadamard) = (1/√2)[[1, 1], [1, −1]]. It maps |0⟩ to |+⟩ = (|0⟩ + |1⟩)/√2 and |1⟩ to |−⟩ = (|0⟩ − |1⟩)/√2. It is the standard way to create an equal superposition, and it converts between the Z basis and the X basis. Applying it twice gives back the original state: H² = I.
- S = [[1, 0], [0, i]]. It multiplies the |1⟩ amplitude by i, a rotation of 90 degrees about the Z axis. Applying S twice gives Z.
- T = [[1, 0], [0, e^{iπ/4}]]. It multiplies the |1⟩ amplitude by e^{iπ/4}, a 45-degree rotation about Z. Applying T twice gives S.
Like Z, the phase gates S and T leave computational-basis probabilities unchanged on their own; their effect shows up once a gate such as H mixes the amplitudes.
CNOT and the Bell state
To do anything that classical bits cannot, qubits must interact. The standard two-qubit gate is the controlled-NOT, or CNOT. It has a control qubit and a target qubit: if the control is |1⟩, it applies X to the target; if the control is |0⟩, it does nothing. Writing two-qubit states as |control, target⟩:
|00⟩ → |00⟩, |01⟩ → |01⟩, |10⟩ → |11⟩, |11⟩ → |10⟩.
Because it acts linearly, CNOT applies this rule to each term of a superposition separately. That is what lets it create entanglement, a joint state that cannot be written as a product of separate single-qubit states.
Trace the standard example, starting from |00⟩:
- Apply H to the first qubit. The state becomes (|0⟩ + |1⟩)/√2 ⊗ |0⟩ = (|00⟩ + |10⟩)/√2. The amplitudes are 1/√2 on |00⟩ and 1/√2 on |10⟩. This is still a product state.
- Apply CNOT with the first qubit as control. The |00⟩ term is unchanged; the |10⟩ term becomes |11⟩. The result is
\( |\Phi^+\rangle = \frac{1}{\sqrt{2}}(|00\rangle + |11\rangle) \).
This is one of the four Bell states. Measuring both qubits gives 00 or 11, each with probability 1/2, and never 01 or 10. The outcomes are perfectly correlated, even though each qubit on its own gives a random result. The entanglement module of the lab shows this correlation directly.
A worked example: interference in three gates
Compare two single-qubit circuits starting from |0⟩.
Circuit A: H then H.
- Start: amplitudes (1, 0).
- After H: (1/√2, 1/√2).
- After the second H: the new |0⟩ amplitude is (1/√2)(1/√2 + 1/√2) = 1, and the new |1⟩ amplitude is (1/√2)(1/√2 − 1/√2) = 0.
- Result: |0⟩ with certainty. The two paths to |1⟩ cancelled.
Circuit B: H, then Z, then H.
- Start: (1, 0).
- After H: (1/√2, 1/√2).
- After Z: (1/√2, −1/√2). Measuring now would still give 50/50.
- After H: the new |0⟩ amplitude is (1/√2)(1/√2 − 1/√2) = 0, and the new |1⟩ amplitude is (1/√2)(1/√2 + 1/√2) = 1.
- Result: |1⟩ with certainty.
A single sign change in the middle, invisible to a measurement at that moment, completely reverses the final outcome. This is interference, and controlling it is the basic mechanism behind quantum algorithms. The example also confirms the identity HZH = X.
Universal gate sets
No finite gate set produces every unitary exactly, but some are universal, meaning any unitary on any number of qubits can be approximated to any desired accuracy by a circuit built from them.
A widely used example is Clifford + T: the gates H, S and CNOT (which generate the so-called Clifford group), together with T. The Clifford gates alone are not enough. By the Gottesman–Knill theorem, circuits made only of Clifford gates, starting from computational basis states and ending with standard measurements, can be simulated efficiently on a classical computer. Adding T breaks this and gives universality. The Solovay–Kitaev theorem guarantees that such approximations need only modestly long circuits.
Gate errors and error correction
Real gates are imperfect. A physical gate might over-rotate, pick up noise from control signals, or let the qubit interact with its surroundings (decoherence). Each error is small, but useful algorithms need very many gates, and errors accumulate.
Quantum error correction addresses this by encoding one logical qubit in many physical qubits, so that errors can be detected and corrected without measuring, and thereby destroying, the encoded information. The threshold theorem shows that if physical error rates are below a certain level (which depends on the code and the noise model), logical error rates can be made arbitrarily small by using larger codes. The cost is a large overhead in physical qubits and operations, which is a central engineering challenge in building quantum computers.
Further reading
- Michael A. Nielsen and Isaac L. Chuang, Quantum Computation and Quantum Information, Cambridge University Press, 2000 (10th anniversary edition 2010), chapter 4 on quantum circuits and chapter 10 on error correction.
- N. David Mermin, Quantum Computer Science: An Introduction, Cambridge University Press, 2007.
- A. Barenco et al., "Elementary gates for quantum computation", Physical Review A 52, 3457 (1995).