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.

The third dimension is time

Switch to the 3-D lattice and turn on the time axis. The bottom layer is the lattice you have been breaking. Every layer above it is the same set of stabilisers measured again, one round later — because a real machine never measures the syndrome once. It measures it continuously, for as long as the computation runs, with gates as faulty as the ones that caused the errors in the first place.

That is why the vertical axis exists. A data error that happens in round 2 flips two stabilisers there and they stay flipped, so the raw outcomes above are all odd — but the decoder does not look at outcomes. It looks at changes between consecutive rounds, called detection events, and a persisting error is exactly one pair of them, at the round it happened. Everything above is quiet. The volume is mostly empty, which is what makes it decodable.

Now the measurement error. One stabiliser reads wrong for one round and right again the next: two detection events stacked vertically on the same plaquette. Look at one slice alone and that lone lit stabiliser looks like a data error matched to the boundary — the decoder would “correct” a qubit that was never wrong, and could walk a chain across the lattice doing it. Look at the stack and the two events sit one round apart on the same site, the cheapest possible pairing. The decoder matches them to each other along the vertical rod and flips nothing. It has told a lie in the readout apart from a flip in the data, and it can only do that because it can see time.

So decoders for real hardware match on this whole space-time volume — rows and columns across, rounds up — with edges that run sideways for data errors, vertically for measurement errors, and diagonally for the faults that do both. The picture the hardware groups publish for below-threshold experiments is this stack. The history shown here is constructed (the placed errors occur in one round and persist, plus one readout blip) and the matching is the 2-D decoder’s lifted to that round with the blip paired to itself, which is the minimum-weight matching for these events; the workbench’s decoder lab runs a genuine space-time decode.

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.

Train a decoder for this code

The matching decoder on this page is one fixed algorithm. The Decoder Lab in the workbench puts it up against decoders that learn: a lookup table, an MLP and a small attention decoder in the shape of AlphaQubit, trained in your browser on this same lattice at d = 3, 5 and 7, with measurement noise as an option. It draws the logical-versus-physical error-rate curves with the threshold crossing, one per decoder, and states how many samples each was trained on — and the learned decoders do exploit the X–Z correlation this page’s matching ignores.

Build this yourself

Every visualization on this page is computed by the same engine as the simulator. Open it to place the gates by hand, up to 16 qubits, free and without an account. Or install Qubit16 so the whole lab is one tap away and works offline.

Open the simulator