The Shor Code
The three-qubit
bit-flip code has a glaring hole: it repairs an X (bit-flip)
error, but a Z (phase-flip) error slips through untouched — and a quantum
error can be either, or a continuous blur of both. In 1995 Peter Shor found the first code
that plugs the hole completely: nine physical qubits that together correct any
single-qubit error whatsoever — bit-flip, phase-flip, or any small rotation in between. It was the
result that turned quantum error correction from a wish into a real possibility.
The clever part is not that nine qubits "store more". It is that a well-chosen encoding, combined
with the act of measuring a syndrome, quietly forces messy continuous noise back into
one of a tiny handful of clean, correctable errors. This page builds the code, then explains that
second idea — the digitization of errors — which is the reason error correction is
possible at all.
Step 1: a phase-flip code
Start by fixing the weakness of the bit-flip code. The bit-flip code catches
X errors because it repeats the bit:
|0\rangle \to |000\rangle, |1\rangle \to |111\rangle.
A phase flip Z is invisible to it — Z does nothing
to |0\rangle and only stamps a minus sign on |1\rangle.
But a Z error is nothing more than an X error
seen in the other basis. Recall the
Hadamard gate
swaps the two bases and turns Z into X. So repeat
the qubit in the Hadamard basis instead:
|0\rangle \to |{+}{+}{+}\rangle, \qquad |1\rangle \to |{-}{-}{-}\rangle.
Now a Z error flips a |{+}\rangle to a
|{-}\rangle — a change we can detect and majority-vote away, exactly
as the bit-flip code voted on 0s and 1s. This is
the phase-flip code: the same idea in a rotated basis, catching
Z where the bit-flip code caught X.
Step 2: concatenate — a code inside a code
The phase-flip code repairs Z but has re-opened the door to
X: a bit flip on a |{+}\rangle qubit is now the
blind spot. Shor's move is to nest the two codes. Take each of the three
|{\pm}\rangle qubits of the phase-flip code and protect it with a
bit-flip code:
|{+}\rangle \to \tfrac{1}{\sqrt2}\big(|000\rangle + |111\rangle\big), \qquad |{-}\rangle \to \tfrac{1}{\sqrt2}\big(|000\rangle - |111\rangle\big).
Substituting these into |{+}{+}{+}\rangle and
|{-}{-}{-}\rangle gives the two nine-qubit codewords:
|0\rangle_L = \tfrac{1}{2\sqrt2}\big(|000\rangle + |111\rangle\big)\big(|000\rangle + |111\rangle\big)\big(|000\rangle + |111\rangle\big),
|1\rangle_L = \tfrac{1}{2\sqrt2}\big(|000\rangle - |111\rangle\big)\big(|000\rangle - |111\rangle\big)\big(|000\rangle - |111\rangle\big).
Read the structure off the diagram below: nine physical qubits arranged as three blocks of
three. The inner bit-flip codes inside each block catch X
errors; the outer phase-flip structure across the blocks catches Z
errors. Because a Y = iXZ error is a bit flip and a phase flip at
once, it trips both checks and is corrected too. Between them the three Pauli errors
X, Y, Z on any single
qubit are all handled.
Worked example: catching a single phase flip
Suppose a Z error strikes qubit 1, inside block 1. Its effect is to
flip the sign inside that block's superposition:
|000\rangle + |111\rangle \;\xrightarrow{\;Z_1\;}\; |000\rangle - |111\rangle.
Notice a Z on any of the three qubits in the block produces the
same block-level sign flip (+ \to -) — so at the block level the whole event
looks like a single phase flip on block 1, turning it from a "+ block"
into a "- block". The outer phase-flip code now compares the signs of the
three blocks: block 1 disagrees with blocks 2 and 3, so a
majority vote across blocks pins the error to block 1 and applies a corrective
phase flip there. Crucially, the check measures only the relative sign between blocks — a
syndrome
— so it never reads the protected data itself. A stray X on some qubit would
instead disturb the 000/111 agreement within
a block, and the inner bit-flip check in that block corrects it independently.
Worked example: a tiny rotation becomes a discrete error
Real noise is not a clean Pauli gate — it is usually a small continuous disturbance, like a
slight over-rotation about the Z axis by a tiny angle
\theta:
e^{i\theta Z} = \cos\theta\, I + i\sin\theta\, Z.
This is a superposition of two errors: with "amplitude" \cos\theta
nothing happened (I), and with amplitude
i\sin\theta a full phase flip Z happened. It is
not a little bit of Z — it is a quantum blend of no error and a
whole Z.
Now measure the syndrome. That measurement asks a yes/no question — "does this block's phase disagree
with the others?" — and, like any quantum measurement, it collapses the blend onto one
of its two branches:
\Pr(\text{no error}) = \cos^2\theta, \qquad \Pr(Z \text{ on that qubit}) = \sin^2\theta.
With probability \cos^2\theta the syndrome reads "clean" and the state is
projected back to the perfect codeword; with probability \sin^2\theta it
reads "phase error on block 1", and the code applies a full Z to fix it.
Either way the continuous parameter \theta has vanished —
the outcome is one of two discrete, correctable possibilities. The measurement digitized the error.
- It encodes one logical qubit into nine physical qubits, built by
concatenating the phase-flip code
(|0\rangle \to |{+}{+}{+}\rangle) with the bit-flip code
(|{\pm}\rangle \to \tfrac{1}{\sqrt2}(|000\rangle \pm |111\rangle)) —
three blocks of three.
- The inner blocks correct X errors and the outer structure corrects
Z errors, so it corrects any single-qubit error
(X, Z, or Y = iXZ).
- Because any single-qubit noise is a linear combination of
\{I, X, Y, Z\}, syndrome measurement digitizes it:
continuous noise collapses onto one discrete Pauli error, which the code then corrects.
- So handling the finite Pauli set is enough to handle all small errors — the
insight that makes quantum error correction possible.
Here is the philosophical heart of the whole field. A skeptic's first objection to quantum error
correction is: qubits live in a continuum, so an error can be an arbitrarily tiny rotation —
and you can't repair infinitely many possible errors with a finite recipe. The answer is that you never
have to. Any single-qubit error E, however exotic, can be written as a
combination of just four operators, E = c_0 I + c_1 X + c_2 Y + c_3 Z. When
the code's syndrome is measured, that measurement is a projection: it collapses the
superposition of errors onto exactly one of those Pauli branches, with the corresponding probability.
So although noise is analog, correction is digital. You design a code that fixes the four Pauli errors
\{I, X, Y, Z\} on each qubit, and measurement does the rest — automatically
rounding every continuous wobble to the nearest correctable Pauli. This error
digitization is precisely why the finite Shor code can defeat the infinite variety of real
physical noise, and why fault-tolerant quantum computing is not a contradiction in terms.
It is tempting to imagine the Shor code works because nine qubits somehow "hold" enough redundancy to
smother any error. That is the wrong picture. The redundancy alone catches only bit and phase flips;
the real engine is that syndrome measurement collapses continuous noise into a discrete Pauli
error that the redundancy can then vote away. Remove the measurement and you have not corrected
anything — you have merely spread the error out.
And do not oversell what the code achieves: the Shor code corrects exactly one
arbitrary single-qubit error. If two qubits are hit before you measure and correct, it can fail, just as
the three-qubit code fails on two bit flips. Protecting against more errors at once needs larger codes
(this is where
stabilizer
codes and the
CSS
construction take over). The Shor code's fame is not its power but its
proof of principle: it showed, for the first time, that an arbitrary quantum error could be
corrected at all.