Stabilizer Codes & the Surface Code
The leading blueprint for fault-tolerant quantum computers.
Writing down the codewords of a code on hundreds of qubits is hopeless. Writing down the handful of Pauli operators that leave those codewords unchanged is easy. That change of viewpoint, the stabilizer formalism, turns error correction into bookkeeping and leads straight to the surface code, today's leading blueprint for a fault-tolerant quantum computer.
What you’ll learn
- Define a stabilizer group and its codespace, and prove that independent generators on qubits leave logical qubits.
- Compute syndromes from commutation relations, and identify logical operators as Paulis that commute with every stabilizer without being one.
- Read parameters and relate the distance to the number of correctable errors.
- Describe the rotated surface code: its checks, logical operators, syndrome-extraction circuits and qubit count.
- Explain the threshold and the scaling of the logical error rate.
Describe a code by what fixes it
In the three-qubit bit-flip code the codewords are . Here is a different description of the same space: it is the set of states that the two operators and both leave unchanged. Each operator compares the parity of two neighbors, and both and pass both tests with eigenvalue .
Two operators instead of a list of states may look like a small saving. For a code on 100 qubits it is the difference between amplitudes and a few dozen Pauli strings. This is the stabilizer formalism, developed by Gottesman, and independently by Calderbank, Rains, Shor and Sloane, in 1996–97.
Think first Why must a stabilizer group be abelian, and why must it exclude ?
Otherwise the codespace is empty. If , a codeword obeys , so . If anticommute, then : the same contradiction.
Elements of square to (since ), so they are Hermitian with eigenvalues , and projects onto the eigenspace of . The factors commute, so projects onto .
Expanding the product gives one term per subset of generators, which is one term per group element because the generators are independent.
A tensor product of Paulis with at least one non-identity factor is traceless, and , cannot lie in .
Only the identity term survives. So independent stabilizers on qubits leave logical qubits. Bit-flip code: , , .
Which of these generating sets does not define a stabilizer code with a non-trivial codespace?
Show the answer
D.
and clash on one qubit ( against ), so they anticommute and no state is a eigenvector of both. Two Paulis commute exactly when they anticommute on an even number of positions: and clash on both qubits and therefore commute.
Syndromes, logical operators and distance
Suppose a Pauli error hits a codeword . For each generator, either or . In the second case
so measuring now gives . Collect these signs into the syndrome :
Every Pauli error falls into exactly one of three classes:
- : detected. A decoder can try to undo it.
- (up to a phase): harmless. It acts as the identity on every codeword.
- but : undetectable and harmful. maps the codespace to itself but changes the encoded state: it is a logical operator.
| Code | Generators | Note | |
|---|---|---|---|
| Bit-flip | , | Corrects one error, but alone is a logical operator, so . | |
| Four-qubit code | , | Detects (but cannot correct) any single-qubit error. | |
| Five-qubit code | and its cyclic shifts | Smallest code that corrects an arbitrary single-qubit error. | |
| Steane | 3 -type and 3 -type, from the Hamming code | Every Clifford gate is transversal. | |
| Shor | 6 weight-2 -type, 2 weight-6 -type | The first quantum code (1995). | |
| Rotated surface code | local weight-4 and weight-2 checks | Only nearest-neighbor interactions on a 2D grid. |
Think first The five-qubit code has generators , , , . What syndrome does a error on qubit 1 produce? (Order the bits like the generators.)
anticommutes with and and commutes with and . On qubit 1 the generators read , so the syndrome is . The 15 single-qubit errors give 15 different non-zero syndromes, and uses all of them: the code is perfect.
Measuring a stabilizer with an ancilla
To read a syndrome bit you must measure the product without measuring the individual qubits, which would collapse the encoded superposition. The trick is to copy the parity onto a fresh ancilla qubit and measure only that.
Data qubits in some state, written in the computational basis; ancilla in . We want to measure .
Apply four CNOTs, each controlled by a data qubit and targeting the ancilla. The ancilla accumulates the parity of the four bits.
If the data is an eigenstate of , every in the superposition has the same parity , and the ancilla factors out. Measuring it returns with certainty and leaves the data untouched.
If the data mixes both parities, measuring the ancilla projects it onto one parity sector: exactly the projective measurement of , with projectors .
Try it. Wires q0–q3 hold one plaquette's worth of data in the state , a eigenstate of both and , and an error has already hit q2. Wire q4 is the ancilla.
An -type check such as uses the same idea in the Hadamard basis: prepare the ancilla in , let it control four CNOTs onto the data, and measure it in the basis. By phase kickback the ancilla ends in according to the eigenvalue .
OPENQASM 3.0;
include "stdgates.inc";
qubit[4] d; // data qubits of one plaquette
qubit a; // ancilla
bit s;
reset a;
h a; // ancilla to |+>
cx a, d[0]; cx a, d[1]; cx a, d[2]; cx a, d[3]; // controlled X on all four
h a;
s = measure a; // 0: eigenvalue +1, 1: eigenvalue -1Measuring an -type check. The controlled- kicks the eigenvalue back onto the ancilla.
The surface code
Place data qubits on a square grid. Each square face between four qubits carries one check, alternating in a checkerboard between -type () and -type (). Along the edges, every other boundary face carries a weight-2 check. Every check involves only neighboring qubits, which is why the surface code suits a 2D chip: each check is measured by one ancilla sitting in the middle of its face.
For there are 9 data qubits and 4 -type plus 4 -type checks. Any -type and -type check overlap on 0 or 2 qubits, so all 8 commute, and they are independent: .
What you just saw is the key geometric fact. A chain of errors lights checks only at its endpoints: in the middle, every check touches the chain twice. An -chain can end silently on the top or bottom edge, where no blue check lies beyond it. A chain stretching from top to bottom therefore commutes with every check without being a stabilizer: it is a logical operator. The shortest has qubits, which is why the code has distance .
A distance- rotated surface code uses data qubits plus one measurement ancilla per check. How many physical qubits does a patch need in total?
Show the answer
49 qubits
data qubits and checks: . In general physical qubits: 17 for , 97 for . Each logical qubit costs physical ones.
Decoding, the threshold and scaling
Measuring all checks yields a syndrome: a set of lit faces. A decoder must guess a correction with the same syndrome. Success means ; failure means is a logical operator. For independent errors of small probability , the most likely explanation is the shortest set of chains that pairs up the lit checks (or links them to a suitable boundary). Finding it is a classic graph problem, minimum-weight perfect matching, solvable in polynomial time.
Real checks are measured by noisy circuits, so a syndrome bit can itself be wrong. The remedy is to repeat the measurement round about times and decode in space and time. When every gate, preparation and measurement fails with probability (circuit-level noise), the surface code has a threshold of roughly (about to , depending on the noise model and decoder). Below it, the logical error per round falls as
Increasing by 2 divides by the error-suppression factor . At , each step buys a factor of 10, and reaching takes : roughly 900 physical qubits per logical qubit. Above threshold (), bigger codes are worse.
A lab measures logical error rates of per round at and at . If the scaling law holds, what should it expect at ?
- : the code has saturated
- : larger codes add more qubits that can fail
Show the answer
B.
, and each step divides by : . means the device is below threshold, so every extra ring of qubits helps.
Key takeaways
- A stabilizer code is the joint eigenspace of an abelian Pauli group without ; independent generators on qubits leave logical qubits.
- The syndrome records which generators anticommute with the error. Logical operators commute with all generators without being stabilizers; the lightest one sets the distance .
- Checks are measured by coupling an ancilla with CNOTs (Hadamard-sandwiched for -type checks) and measuring only the ancilla.
- The rotated surface code uses qubits with local checks; its logical operators are chains across the patch.
- Below a circuit-level threshold near , : each step divides the logical error by , as experiments now confirm.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
A stabilizer code on qubits has independent generators. What are the number of logical qubits and the codespace dimension?
- , dimension
- , dimension
- , dimension
- , dimension
Show the answer
C. , dimension
, the state space of qubits. Each independent generator halves the space.
A Pauli operator commutes with every stabilizer generator. Which statement is correct?
- is either a stabilizer (harmless) or a logical operator (undetectable and harmful)
- is always harmless, because it produces a trivial syndrome
- is always a logical error
- is detected by the syndrome measurement
Show the answer
A. is either a stabilizer (harmless) or a logical operator (undetectable and harmful)
A zero syndrome means . If it acts trivially on codewords; if it silently changes the encoded state. The distance is the minimum weight of the latter kind.
On the surface code, an flip on the top-middle qubit and one on the top-right qubit light the same single blue face, so the decoder cannot tell them apart. Why is that harmless?
- The decoder always picks the qubit that actually flipped
- errors cannot damage a surface code; only errors can
- The two qubits are entangled, so they are effectively one qubit
- Their product, on those two qubits, is a stabilizer (the red half-moon), so correcting the "wrong" one leaves a harmless stabilizer
Show the answer
D. Their product, on those two qubits, is a stabilizer (the red half-moon), so correcting the "wrong" one leaves a harmless stabilizer
If the error was on one qubit and the decoder applies on the other, the net effect is on the pair: exactly the weight-2 check on the top edge, which acts trivially on the code. Quantum codes are often degenerate: different errors with the same syndrome need not be distinguished.
A surface code runs at half the threshold (). Going from to changes the logical error rate by roughly what factor?
- It halves
- It drops by about
- It drops by about
- It increases, because more qubits can fail
Show the answer
B. It drops by about
per step of in distance, and is two steps: . Equivalently, the exponent goes from 3 to 5, and .
Why are surface-code checks measured through an ancilla rather than by measuring the four data qubits directly?
- Ancilla measurements are faster
- Data qubits cannot be measured in the basis
- Measuring the data would reveal (and collapse) the encoded information; the ancilla records only the parity
- The ancilla corrects the error automatically
Show the answer
C. Measuring the data would reveal (and collapse) the encoded information; the ancilla records only the parity
Measuring the data qubits individually measures far more than the product : it collapses the logical superposition. Coupling to an ancilla and measuring only the ancilla implements the projective measurement of the product, leaving the code state intact.
Go deeper
- The Stabilizer Formalism · Describing states and codes by the Paulis that fix them.
- Surface Code Decoding & Thresholds · Matching decoders, thresholds and logical error rates.
- Beyond the Surface Code: qLDPC Codes · Higher rates with long-range connectivity.
Further reading
- D. Gottesman, Stabilizer Codes and Quantum Error Correction, PhD thesis, Caltech (1997), arXiv:quant-ph/9705052.
- M. A. Nielsen & I. L. Chuang, Quantum Computation and Quantum Information, §10.5 (Cambridge, 10th anniv. ed., 2010).
- A. G. Fowler, M. Mariantoni, J. M. Martinis & A. N. Cleland, "Surface codes: Towards practical large-scale quantum computation", Phys. Rev. A 86, 032324 (2012).
- Google Quantum AI and collaborators, "Quantum error correction below the surface code threshold", Nature (2025), arXiv:2408.13687.