Skip to main content
All visualizations
Advanced

The Surface Code

Why one usable qubit costs a hundred real ones — and what happens when you do not spend enough.

The Surface Code visualization

Click a circle — or tab to it and press Enter — to inject a X error. Rings show the chains the decoder proposes to flip: amber for the X channel, violet for the Z channel. The dashed lines mark one representative of each logical operator; a residual chain that crosses the lattice between the two matching boundaries is a logical error.

The syndrome, in words

No errors placed yet. Every stabiliser reads even parity.

Stabiliser measurement outcomes and the decoder’s response for the currently placed errors on a distance-5 surface code.
ChannelErrorsStabilisers litCorrection weightOutcome
X errors, seen by Z stabilisers000corrected
Z errors, seen by X stabilisers000corrected

No logical error: the residual chain is a product of stabilisers, which acts as identity on the encoded qubit.

What the machine actually sees

You cannot look at a qubit. Reading it collapses it, and reading an encoded qubit destroys the very superposition you were trying to protect. So error correction never measures the data. It measures parities: the diamonds on the lattice each check whether an even or odd number of their neighbours has flipped.

A parity carries no information about the state — it is the same whether the logical qubit is |0⟩, |1⟩ or anything between — which is exactly why measuring it does no damage. Place a single error and watch: two diamonds light up, at the two ends of the chain you created. That pair of lit diamonds is called a defect pair, and it is the entire input to the decoder.

The decoder is guessing, and it can guess wrong

Two lit diamonds tell you the error chain ends there. They do not tell you which path it took. The decoder assumes the shortest one, because at low error rates short chains are exponentially more likely than long ones. That is minimum-weight perfect matching, and it is what runs here — exact, over distances measured on the real syndrome graph, not a Manhattan approximation.

Now place a chain of 3 errors straight down the left column of the d = 5 lattice. The syndrome looks identical to a chain of 2 errors coming from the other side, so the decoder takes the shorter route — and error plus correction now form a complete path from one boundary to the other. Every stabiliser reads even. Nothing is lit. Nothing is wrong, as far as the machine can tell. And the logical qubit has been flipped.

That is what “distance d” buys: you need at least 3 simultaneous errors before that can happen. Fewer than that, and the shortest explanation is always the right one.

The threshold, measured here

Press Run random rounds and change d. Below a critical physical error rate, a bigger code has a lower logical error rate — that is the whole promise, and it compounds: each step in d buys another factor. Above it, a bigger code is worse, because you have added more places for errors to appear than the extra redundancy can pay for.

MEASURED for this simulation, 4,000 rounds per point (the curves cross between 8% and 10%):

Logical error rate against physical error rate for code distances 3, 5 and 7, from 4,000 rounds per cell of this page’s own simulation.
pd = 3d = 5d = 7
1%0.30%0.05%0.00%
2%1.20%0.35%0.20%
3%3.15%1.32%0.43%
5%7.10%4.45%3.15%
8%15.85%14.85%12.53%
10%22.25%23.08%22.93%
12%30.78%31.90%35.68%
15%38.02%45.00%50.60%
20%51.65%59.80%65.97%

Do not read 9% as the surface code’s threshold. This simulation assumes perfect stabiliser measurement and a single round of correction. Real machines measure the syndrome with the same faulty gates that caused the errors, repeatedly, and must decode in three dimensions with time as the third. That drops the threshold to roughly 1%, which is the number the hardware industry is actually chasing.

Why a logical qubit costs so much

A distance-5 patch is 25 data qubits and 24 ancillas: 49 physical qubits, for one logical qubit that is still not perfect, only better. And the payoff is only exponential in d if p stays below threshold, so the answer to “we need a lower logical error rate” is always “a bigger patch”.

Estimates for factoring a 2048-bit RSA key with surface-code-protected qubits land in the millions of physical qubits, dominated by exactly this overhead. That number is why the interesting engineering question is not “can we build a qubit” but “can we build one whose error rate leaves enough headroom below threshold that the patch does not have to be enormous”.

One honest limitation of this page: X and Z errors are decoded independently. A Y error is an X and a Z on the same qubit, and a decoder that knew that could do better with the same syndrome. Real decoders exploit the correlation; this one does not.