Keep it alive
Noise flips qubits at random, and you cannot look at them. Keep a message alive with nothing but two lights that show whether the qubits match.
New to qubits: start with the short guide, Quantum basics.
The problem
Qubits are fragile. Heat, stray fields, and small control errors change them at random, and this noise is why today’s machines cannot run long programs. The normal fix for a noisy bit is to keep copies, then take the majority. A qubit blocks this twice: nobody can copy an unknown qubit, and reading it to check it destroys what it holds.
The way out is to spread one message over three qubits. On this page, the message is the state of one qubit, not text that you can read. It is a mix, some chance of 0 and some chance of 1. The three qubits together hold a mix of 000 and 111, with the same chances that the message had for 0 and 1. This is one message on three qubits, and it is not three copies: read any one qubit, and you get only one 0 or 1, and the message is gone.
To find errors, you ask only whether two qubits match. This is called their parity. If the three are all 0 or all 1, each pair matches either way. So a parity light, which shows Same or Differ, tells you nothing about the message. It changes only when noise puts the qubits out of step.
- Noise is a random gate. Here, X (a bit flip) strikes each qubit with probability p.
- The no-cloning theorem forbids |ψ⟩ → |ψ⟩|ψ⟩|ψ⟩. So α|0⟩ + β|1⟩ is encoded as the entangled state α|000⟩ + β|111⟩, which two CNOTs produce.
- Each code state is a +1 eigenstate of the stabilizers Z₁Z₂ and Z₂Z₃. Their measured values, the syndrome, locate one X error and reveal nothing about α or β.
Each stabilizer is measured with an ancilla qubit and two CNOT gates, on a state vector of five qubits. Gates and readout can fail, as you can set in Part 2.
Part 1
Keep the message alive
Your goal
Keep Alice’s message alive for 20 rounds. In each round, noise flips each qubit between 0 and 1, with a 5% chance for each one.
How to play
- You cannot see the qubits, only the two lights: A compares qubits 1 and 2, and B compares qubits 2 and 3.
- Work out which single qubit explains the lights, and flip it back.
- Start with perfect checks.
Your score is the number of rounds the message survives. A plain qubit at the same noise level runs next to yours, for comparison. You see the score only at the end, because you cannot look at the message during the game.
Each round applies X to each data qubit with p = 0.05, then measures the syndrome. In noisy mode, each CNOT is followed by X on one of its two qubits with probability 0.02, and each readout is wrong with probability 0.02. Apply X to return to the code space. Decoding assumes one error, so two data errors lead it to a logical error. The logical state is revealed at the end.
Noisy checks act as on a real machine. Two extra qubits run each reading through gates that fail 2% of the time, and a failed reading can show a false difference, or flip a data qubit. You can read the lights again before you trust them, but each reading is another chance for a gate to fail.
| Round | Noise flipped | Check failures | You flipped |
|---|
Part 2
When is it worth it?
Three qubits give noise three places to strike, and each check adds gates that can fail, so more qubits are not always better.
With perfect checks, the code wins at every noise level below 50%. With checks that also fail, it wins only between two limits. At very low noise, the checks add more errors than the noise does. Reading each check three times helps little, because a failed gate can flip a data qubit, and no reading undoes that.
How to read it
- Move the noise slider. In the table and on the chart, the lower failure rate wins.
- Set the check failure to 2%, then press Zoom in: low noise.
- Find where the code’s line crosses below the plain qubit’s line. From there, the code helps, until a second crossing at high noise that All noise shows.
A plain qubit fails with probability p. The code fails on two or three errors: 3p²(1 − p) + p³ = 3p² − 2p³. This is below p for p < ½ when the checks are perfect. With check failure g, a single fault in the check circuit can leave a data error, so the rate does not fall to zero with p. It has a floor near a multiple of g, and the code beats a plain qubit only in a window. The rate here is failures divided by rounds run, over many messages, each for up to 20 rounds.
| Message on | Fails each round | Alive after 20 rounds |
|---|
Show the numbers for perfect checks
| Noise | Plain qubit fails | Three qubits fail |
|---|
Part 3
The catch: a second kind of error
Noise can also change a qubit’s phase, the hidden sign you can meet in the circuit puzzle. A phase flip leaves the 0s and 1s as they were, so the lights have nothing to compare. The same idea can also compare phases in place of bits. That gives a second code, the phase-flip code.
Use the buttons to strike the message yourself, one flip at a time. The match shows how close the state still is to Alice’s message. Try each kind of flip on the bit-flip code, and then switch to the phase-flip code.
Watch the lights before the match. A light that is on means the code has seen the error and can fix it, so even a match of 0% comes back to 100% after the fix. The real damage is a flip that lights nothing. The match falls, to 36% for this message, and nothing shows it or repairs it.
Z on any qubit of α|000⟩ + β|111⟩ is a logical Z, and it commutes with Z₁Z₂ and Z₂Z₃, so the syndrome stays silent. The phase-flip code is the same code in the X basis, α|+++⟩ + β|−−−⟩ with stabilizers X₁X₂ and X₂X₃. There, Z errors show, and X errors are the logical ones. Here, |α|² = 0.2, and a silent logical error leaves a fidelity of (|α|² − |β|²)² = 36%, whatever the relative phase.
| Strike | Qubit 1 | Qubit 2 | Qubit 3 |
|---|---|---|---|
| Bit flip | |||
| Phase flip |
Match with the message:
Part 4
Errors start small
Until now, each error was a whole flip. Much real noise starts as a small drift: each arrow tips a little, so each qubit is partly flipped. This looks like a problem, because a fix can only flip a qubit all the way. Other noise is different, such as a qubit that loses energy, and this part does not model it.
Reading the lights solves it. The reading has to give a yes or a no, so the partial flip becomes either no flip or a whole flip, and small drifts almost always give no flip. Let the qubits drift, watch the match drop, then read the lights. The checks here are perfect, so you see this effect alone.
Each drift applies Rx(θ) to each data qubit. The syndrome measurement projects the state onto a sector with a definite X error, with probability set by sin²(θ/2) and cos²(θ/2). A correction for X then restores the code state. So a code for discrete errors also corrects coherent noise. Errors of θ add as amplitudes between readings, so the chance of a flip grows as the square of the time between them. This is the quantum Zeno effect, as in the bomb tester.
Match with the message:
When to read
Run 20 drifts in a row, 400 times, and read the lights in one of two ways. This shows why a real machine reads its lights again and again.
- Average match, reading after each drift
- Average match, reading only at the end
Part 5
The real design: the surface code
Real machines use a grid. The round cells are data qubits, and the square cells are check qubits, each one a light like A and B. The thin lines join each check to the qubits it watches, up to four. The grid has both kinds of check from Part 3: B squares show bit flips, and P squares show phase flips. So it can catch both kinds on the same qubits.
A line of flips lights only the checks at its two ends. Try it: flip one qubit, then the one below it, and see the lit checks move. Then make a line of bit flips from top to bottom.
This is the rotated surface code at distance d, with d² data qubits and d² − 1 ancillas. Errors make chains, and the syndrome marks the ends of each chain. A chain across the lattice commutes with all the stabilizers and is a logical operator, so the shortest logical error has weight d. The grid here has d = 3.
Does a bigger grid help?
A bigger grid needs a longer line of flips to fool it. The length of the shortest such line is called the grid’s distance. But a bigger grid also has more qubits and gates that can fail. Which effect wins depends on how good the gates are.
This simulation has every qubit, gate, and reading fail at the rate you choose. A program called a decoder works out the flips from the lights and undoes them. When it guesses wrong, the whole message flips. This is called a logical bit flip, and the chart counts how often it happens.
How to read it
Find where the lines cross. That error rate is called the threshold. Below it, a bigger grid is better. Above it, a bigger grid is worse.
Good hardware today makes about one error in 1,000 gates, which is 0.1% on this scale. This simulation’s noise is gentler than a real chip’s, though: it leaves out errors on qubits that wait, and qubits that leak out of 0 and 1. So at the same rate, real hardware does worse than these lines, and needs more qubits. This simulation also counts only logical bit flips. The message can also suffer a logical phase flip, so its true failure rate is higher.
A logical |0⟩ is stored for d rounds, then read out. Noise is uniform with rate p: depolarizing on data each round and after each H and CNOT, and flips on each reset and readout. The simulator propagates Pauli errors, which is exact for this noise. The decoder is uniform-weight union-find (Delfosse and Nickerson, 2021) on a graph built from each single fault. It is faster and weaker than the best decoders. Rates are per round, and they count only logical X, since a stored |0⟩ cannot show a logical Z. Lines come from up to millions of shots, with a point only where a run had at least 10 failures.
| Distance | Qubits | Failures per round |
|---|
The lines come from a long run made ahead of time. You can repeat a shorter run in your browser. It takes about 25 seconds, and your results appear as rings.
What this shows
You can repair a message you cannot read, because the lights report on the qubits and never on the message. This has a limit: a code helps only when noise is low enough, and each code misses some errors. On a real machine, no person watches the lights. A fast ordinary computer reads them and sends the fixes, again and again, for as long as the program runs.
Each three-qubit code stops one kind of flip and has no defence against the other. Peter Shor’s 1995 code nests one inside the other, on nine qubits, and repairs any error on one qubit. Real machines use a larger design, the surface code. The qubits in the hardware are called physical qubits, and the one reliable qubit that a code holds is called a logical qubit. It takes many physical qubits to hold one logical qubit, which is why a machine that breaks today’s keys needs about a million physical qubits.
The surface code lines in Part 5 cross near , a long way below the 50% of Part 2. This is a rough estimate of the threshold, from small codes in this simulation. Hardware must beat the threshold before a bigger code helps. In 2024, Google ran a surface code on its Willow chip and showed that larger codes made fewer errors.
These results show how a threshold behaves, and they do not predict any real chip. The simulation leaves out qubits that leave the 0 and 1 states, errors that strike many qubits at once, qubits that differ from each other, and small steady drifts in the grid. Better decoders also do better than the one here.
Part 4 shows why a discrete code can correct continuous noise, for X-type rotations. The same logic extends to Z-type rotations, given a code that has both kinds of stabilizer. Here, the noisy checks of Part 2 have only X faults, so they cannot damage the phase of the message, and a real check circuit has Z faults too.
Shor’s [[9,1,3]] code concatenates the phase-flip and bit-flip codes and corrects any one-qubit error. The surface code needs only nearest-neighbor checks. Published circuit-level thresholds vary with the code, noise model, and decoder. One 2020 study of the toric code, with its own noise model, gives 0.38% to 0.62% for union-find and 0.65% to 0.72% for matching. The crossing here comes from distances 5 and 7, so it is not a precise threshold. It also sits above the published values partly because this noise model has no idle errors on waiting qubits and no leakage, so the two are not directly comparable. Good physical qubits make roughly one error in 1,000 two-qubit gates. Below threshold, the logical rate falls exponentially with distance. The projection to a target rate assumes that the factor stays the same, which a real device has no reason to do, and it omits leakage and correlated errors.