Quantum Error Correction
Decoherence threatens every qubit — the 3-qubit bit-flip code shows how redundancy and syndrome measurement fight back.
Real qubits are fragile. Stray fields, heat, and unwanted interactions cause decoherence and noise, randomly disturbing the delicate amplitudes. Worse, the obvious classical fix — “just copy the bit three times and take a majority vote” — is blocked by the no-cloning theorem and by the fact that measuring a qubit destroys its superposition. Quantum error correction has to detect and repair errors without ever reading or .
The 3-qubit bit-flip code is the simplest example. Step through it below: encode one logical qubit into three, let noise flip one of them, measure the syndrome to locate the flip, and apply a correction.
Encode: α|0⟩ + β|1⟩ → α|000⟩ + β|111⟩ using two CNOTs. The three qubits now agree.
Encoding
We spread one logical qubit across three physical qubits using two CNOTs:
This is not cloning — there is still only one quantum state, now entangled across three qubits. The amplitudes are never duplicated; only the classical pattern (all-zeros vs. all-ones) is made redundant.
Detecting the error
Suppose noise flips qubit , turning the state into . We must find the culprit without learning or . The trick is to measure parities rather than the qubits themselves:
- = parity of qubits and (do they match?)
- = parity of qubits and
These two bits form the syndrome. They reveal whether neighbors disagree, but reveal nothing about the encoded amplitudes — so the superposition survives the measurement. The mapping is unambiguous:
| flipped qubit | ||
|---|---|---|
| 0 | 0 | none |
| 1 | 0 | qubit 0 |
| 1 | 1 | qubit 1 |
| 0 | 1 | qubit 2 |
Correcting it
Once the syndrome names the offending qubit, applying an gate flips it back, restoring and therefore the logical state. The correction is itself a quantum operation, so the protected superposition is recovered exactly — no information was lost. Try the none option in the visualizer to confirm that a clean round produces syndrome and leaves the state untouched.
Limits and the bigger picture
This code only fixes a single bit flip; two simultaneous flips would fool the majority and produce a logical error. It also does nothing about phase flips (the -type error). The famous 9-qubit Shor code stacks a bit-flip code and a phase-flip code to correct any single-qubit error, and modern surface codes extend the idea to large 2D lattices. The strategy is always the same: redundancy plus syndrome measurements that diagnose errors without disturbing the data — the foundation of fault-tolerant quantum computing.
The Shor code (9 qubits)
The 3-qubit code above fixes a bit flip () but is blind to a phase flip (). The fix for phase flips is elegant: a phase flip in the standard basis is a bit flip in the Hadamard basis. So the phase-flip code is just the bit-flip code conjugated by Hadamards — encode with on every qubit, and a error becomes an error that the same parity machinery catches:
Peter Shor’s 9-qubit code concatenates the two: it nests a bit-flip code inside a phase-flip code, encoding one logical qubit into physical qubits arranged as 3 blocks of 3.
Two layers of syndrome measurement then cooperate:
- Inner (bit-flip) syndrome — within each block of 3, the same parity checks as before locate a single error and fix it with an .
- Outer (phase-flip) syndrome — a on any qubit in a block flips that block’s sign (). Comparing the signs across the three blocks locates which block carries the phase error and fixes it with a .
Because any single-qubit error is a combination of , , and , correcting bit flips and phase flips independently corrects every single-qubit error — even a small continuous rotation, which the syndrome measurement discretizes into one of these cases. Inject a bit flip, a phase flip, or both on any qubit and step through detection and correction:
Encode 1 logical qubit into 9: three blocks, each (|000⟩±|111⟩). The inner layer guards bit flips, the outer layer guards phase flips.
Takeaways
- Qubits suffer decoherence; no-cloning and measurement collapse rule out naive copying, so QEC must repair errors blindly.
- The 3-qubit code encodes as and corrects one bit flip.
- Syndrome parity measurements locate the error without revealing ; an gate then fixes it. Bigger codes handle phase and multi-qubit errors.