Shor Nine-Qubit Code
In 1995 quantum computing faced an objection that looked fatal. Classical machines fight noise by copying a bit many times and voting, but the no-cloning theorem forbids copying an unknown quantum state, and every measurement disturbs the thing it reads. If you cannot copy and cannot look, how could you ever protect a qubit? Peter Shor's nine-qubit code is the explicit answer — the first quantum error-correcting code, and a constructive proof that the objection is wrong. It encodes one logical qubit into nine physical qubits so that an arbitrary error on any single physical qubit — not merely a discrete bit flip or phase flip , but any operator on that qubit, including coherent over-rotations and amplitude damping — can be detected and reversed without ever measuring, or disturbing, the logical information. The construction is a two-layer sandwich. The three-qubit bit-flip code beats errors by majority vote but is blind to ; its Hadamard-conjugate, the phase-flip code, beats but is blind to . Neither alone is a genuine quantum code. Shor's move was to concatenate them: take the phase-flip code on the outside and re-encode each of its qubits with a bit-flip block on the inside. The nested code inherits both protections at once, and because errors discretize, correcting the Pauli set on each qubit is enough to correct the entire continuum. Two ideas that were each half a code become, when stacked, the whole of one — the gateway to the stabilizer formalism, CSS codes, and the threshold theorem that makes scalable quantum computing possible.
- The Shor nine-qubit code is the first quantum error-correcting code: it encodes one logical qubit in nine physical qubits so that an arbitrary error on any single qubit can be detected and corrected.
- It is built by concatenation — the three-qubit phase-flip code on the outside, each of its qubits re-encoded by a three-qubit bit-flip code — giving a stabilizer code.
- Because errors discretize, correcting the Paulis on each qubit automatically corrects every continuous single-qubit error, amplitude damping and small rotations included.
- Bit flips are caught by six stabilizers comparing qubits inside each block; phase flips are caught by two weight-six stabilizers comparing the relative sign of the blocks.
- It has distance and corrects error; the minimal logical operators are and , both weight three.
- It is a (highly redundant) CSS and degenerate code — the pedagogical ancestor of the leaner five-qubit and Steane seven-qubit codes and of the surface codes running on hardware today.
- Key idea: concatenate phase-flip protection (the outer code, against ) with bit-flip protection (the inner blocks, against ); because , correcting independent and errors automatically corrects , and by discretization this covers every single-qubit error.
Where this lives today
The Shor code itself is too redundant for a modern processor, but its ideas are the working vocabulary of every quantum error-correction experiment. Its direct descendant, the nine-qubit Bacon–Shor code — a subsystem variant of the same layout — was run fault-tolerantly on thirteen trapped-ion qubits by the Maryland group (Egan et al., Nature 598, 281 (2021)), demonstrating an encoded logical qubit whose error rate fell below that of its physical constituents. The concatenation idea Shor introduced, recursively nesting a code inside itself to drive the logical error rate down as a double-exponential in the number of levels, is the engine behind the threshold theorem: below a critical physical error rate, arbitrarily long computations become reliable. Today the field has largely moved from concatenated codes to topological surface codes, which are also CSS and also degenerate but are laid out on a two-dimensional lattice with only local checks — Google's superconducting processors have shown a distance-five and then a distance-seven surface-code logical qubit whose error rate decreases as the code grows (the below-threshold result of Nature 2024), the scaling behaviour Shor's construction first made conceivable. Every one of these systems measures stabilizers exactly as the nine-qubit code taught: joint parities read by ancilla qubits, never touching the logical information, digitizing continuous noise into a discrete Pauli that a lookup table corrects.
The physical picture
Protect a secret two ways at once. The bit-flip code writes the same bit into three qubits so a single flip loses a majority vote in the computational basis; the phase-flip code does the identical thing in the basis, where a error looks like a bit flip. A physical qubit can suffer both kinds of damage, so Shor simply stacks the two protections — three copies of a three-copy code — and gets robustness in both bases simultaneously. The outer layer decides which block carries a phase error; each inner block decides which qubit inside it carries a bit-flip error. The first figure draws that layered architecture: an outer phase-flip code whose three "qubits" are themselves bit-flip blocks.
Why does a finite set of discrete corrections defeat a continuum of possible errors? The answer is linearity plus measurement. An arbitrary error on qubit is a complex combination of the four Paulis acting there. When you measure the eight stabilizers you do not read the logical state — you read only relations between qubits — and that measurement projects the corrupted superposition onto one definite Pauli branch, "collapsing" the continuous error into a discrete one. A fixed Pauli recovery, chosen by the syndrome, then restores the codeword exactly; the continuous error parameters are never needed and never learned. The second figure makes this concrete with real syndrome bits: it tabulates the syndromes that specific single-qubit errors produce, and shows how two errors can conspire to a silent logical fault.
Read across the third block-tuple of the bit-flip syndrome as "which qubit inside the block," and across the two phase bits as "which block." The last row is the whole point of the distance: two well-placed errors reach a weight-three logical operator, and no code of distance three can see that coming.
The core equations
The logical basis states are the concatenation written out in full: each of the three blocks is a GHZ-like triple , and the outer sign encodes the logical bit. Everything else — stabilizers, logical operators, distance — follows from reading these two states.
where: — the encoded logical zero on nine qubits; — one inner bit-flip block, an unnormalized in the outer phase-flip layer; — normalization, since each block has norm and there are three of them, . Read it as three GHZ triples glued with plus signs. The logical one flips every outer sign to minus. That single sign flip, applied to all three blocks at once, is exactly the logical operation of the code, as we verify below.
where: — the "minus" block, encoding the outer logical of the phase-flip code. Note : the blocks are orthogonal because , so the two logical states are perfectly distinguishable in principle yet inaccessible to any single-qubit measurement. The codespace is the simultaneous eigenspace of eight independent, mutually commuting stabilizer generators: six two-body operators comparing qubits inside each block, and two six-body operators comparing the relative sign between blocks. This clean split into -type and -type checks is the defining CSS structure.
where: — compares two qubits within a block, detecting bit flips ( errors); and — compare adjacent blocks, detecting phase flips ( errors); — the abelian group generated by these eight Paulis. Any -type generator overlaps any -type generator on an even number of qubits, so all eight commute and can be measured together; eight independent generators on nine qubits leave logical qubit. The logical operators live in the normalizer but outside . Strikingly, logical is built from 's and logical from 's — the fingerprint of the concatenation, in which "flip the outer sign" () is a -type operation and "read the outer sign" () is an -type one.
where: — logical Pauli-, swapping ; the canonical form reduces modulo stabilizers to the weight-three (one per block); — logical Pauli-, applying a relative phase; reduces to the weight-three ( on one full block). The symbol means "equal up to a stabilizer," which does not change the action on the codespace. They anticommute, , as a logical Pauli pair must. Counting these weights gives the code's headline parameters. The distance is the minimum weight over all nontrivial logical operators, and here that minimum is three, so the code corrects one arbitrary single-qubit error.
where: — physical qubits; — logical qubits ( minus the eight generators); — code distance, the lightest logical operator's weight; — arbitrary single-qubit errors correctable. The five-qubit perfect code achieves the same with , so the Shor code is deliberately redundant — its transparency, not its efficiency, is the point. Finally, the abstract criterion that certifies all of this is the Knill–Laflamme condition. It is the exact, if-and-only-if statement of when a set of errors is correctable, and the Shor code satisfies it for every weight- Pauli.
where: — the logical basis states ; — correctable errors, here all Paulis of weight ; — a Hermitian matrix independent of the logical labels ; — Kronecker delta. The says different errors never leak information distinguishing from ; the -independence of says the errors deform both logical states identically. Degeneracy shows up as a singular — several errors sharing a syndrome — which the Shor code has and which does no harm.
The goal is to construct the Shor code from the ground up as an outer phase-flip code whose three qubits are each replaced by an inner bit-flip block, and to show that this nesting produces a genuine quantum code — one that corrects both and on any single qubit — where each three-qubit layer alone corrects only one error type and is not a quantum code at all. We build the encoding map layer by layer and read off why the eight stabilizers take the form they do.
Step 1. Start with the outer three-qubit phase-flip code, which encodes and and is stabilized by and on its three qubits . Why: the phase-flip code is the Hadamard transform of the bit-flip code, so it corrects a single (which is a bit flip in the basis) but is completely blind to — it is only half a code.
Step 2. Replace each outer qubit by an inner three-qubit bit-flip block through and . Substituting into Step 1 gives exactly equations (1) and (2). Why: the inner code corrects a single inside each block by majority vote, patching the outer code's blind spot without disturbing its phase protection.
Step 3. Lift the stabilizers. Each inner block contributes its two bit-flip checks (and the analogues on blocks B, C), giving six -type generators. Why: a bit flip inside a block changes the parity of neighbouring qubits, which is precisely what the two operators per block read out — three qubits, two independent parities, exactly enough to locate one flip.
Step 4. Lift the outer checks. The outer acting on a qubit becomes on its block (it flips into itself up to the sign it is testing), so and . Why: comparing the relative sign of two blocks requires flipping all six of their qubits at once, which is why the phase checks are weight-six rather than weight-two.
Step 5. Collect: six plus two weight-six generators, all commuting, eight independent operators stabilizing a two-dimensional space. A single error is caught by the inner checks of its block; a single error is caught by the outer checks; a single trips both. Why: because the two error types are read by disjoint check types, the two layers of protection do not interfere, and the concatenated code corrects what neither layer could alone. *Note: each of the nine single-qubit Paulis yields a nonzero syndrome on the eight generators — confirming that every single-qubit error is detectable and that the encoding reproduces equations (1)–(3).*
Go deeper · Derivation B · 2 minCorrecting an arbitrary single-qubit error by discretization
The goal is to prove the property that makes the Shor code a true quantum code and not merely a corrector of discrete flips: the ability to reverse the three Paulis on each qubit implies the ability to reverse any single-qubit operation on that qubit, including non-unitary noise such as amplitude damping and coherent over-rotations, even though those errors form a continuum. We take a general error, apply it to a codeword, and trace it through the syndrome measurement to see the continuum collapse to a discrete choice.
Step 1. Expand the error. Any linear operator on qubit is a combination of the four Paulis, , because spans the space of matrices. Why: this is the algebraic heart of the argument — a continuous, possibly non-unitary error lives in a four-dimensional space with a discrete Pauli basis.
Step 2. Apply it to a codeword. Linearity gives , a superposition of four branches, one per Pauli. Why: the corrupted state is not "a little bit wrong" in some fuzzy way — it is a coherent sum of four cleanly-labelled error branches.
Step 3. Measure the eight stabilizers. On qubit the operators carry distinct syndromes (up to the harmless block degeneracy), so the measurement projects the superposition onto a single branch with probability , yielding a definite Pauli error and its syndrome. Why: stabilizer measurement is a projective measurement in the "error basis," and it collapses the continuous coefficients into one discrete outcome — you learn which Pauli, never the amplitudes.
Step 4. Recover. Knowing the syndrome fixes the Pauli ; applying gives , the exact codeword. Why: Paulis are self-inverse up to phase, so the recovery is a single fixed gate, and the state is restored perfectly with no residual dependence on .
Step 5. Conclude for channels. Writing a general noise channel as with each supported on one qubit, every Kraus branch is corrected by the argument above, so restricted to single-qubit support is corrected exactly. Why: correctness for each Pauli, plus linearity, upgrades automatically to correctness for arbitrary — including dissipative — single-qubit noise.
The substance of this argument is the orthogonality of single-qubit Pauli syndromes, which can be confirmed by commuting each of against the eight generators.
Go deeper · Derivation C · 2 minThe distance is exactly three
The goal is to prove that the minimum weight of a nontrivial logical operator is three, which fixes and hence , and to exhibit the lightest logical operators explicitly — correcting a common error that mislabels as a logical operator when it is in fact a detectable error. A logical operator must commute with all eight stabilizers (so it is undetectable) yet lie outside (so it acts nontrivially on the codespace); we hunt for the lightest such Pauli.
Step 1. No weight-one logical exists. Every single-qubit Pauli is detected: or anticommutes with a check of its block, and anticommutes with a weight-six check (a single overlaps on one qubit, an odd count). So . Why: with a nonzero syndrome, a weight-one error is caught and corrected, so it can never be a silent logical operation.
Step 2. No weight-two logical exists. A representative trap is — it is not weight two, but it illustrates the check: overlaps on three qubits, an odd count, so it anticommutes and is detected, not logical. Genuine weight-two Paulis are likewise caught: for instance overlaps on the single qubit 4 and so anticommutes with it. Every weight-two Pauli triggers some generator. So . Why: distance is about undetectable operators, and an odd overlap with any generator means detection — light Paulis cannot hide.
Step 3. A weight-three logical exists — logical . Take : it commutes with every check (overlapping on qubits 1,2 and on qubits 2,3, each an even count) and with both checks trivially, yet equals modulo the stabilizer , so it is a nontrivial logical of weight three. Why: flipping one whole block's phase reference is undetectable because it respects every parity check, but it is exactly the logical action on the outer code.
Step 4. A weight-three logical exists — logical . Take , one per block: it overlaps each weight-six check on exactly two qubits (even, hence commuting) and commutes with all checks, yet equals modulo three stabilizers. Why: this is the two-error failure mode made honest — two of its three 's are the uncorrectable pair , and the third completes the silent logical bit flip.
Step 5. Conclude. Both nontrivial logicals reach minimum weight three and none is lighter, so and : exactly one arbitrary single-qubit error is guaranteed correctable. Why: distance three is the smallest distance that corrects a full error, and it is the price of the Shor code's simplicity.
One can confirm by enumerating all weight- Paulis on nine qubits against the eight generators — every one has a nonzero syndrome — and then exhibiting the weight-three normalizer elements and . Note that is detected, not logical.
Limiting cases
Pushing the code into special regimes sharpens exactly what "single-error correction" buys and what it does not.
| Case | Result | Meaning |
|---|---|---|
| Single Pauli error | Perfectly corrected: each yields a definite (or harmlessly degenerate) syndrome and a unique recovery Pauli. | |
| Arbitrary single-qubit error | Corrected by discretization: the syndrome projects onto one Pauli branch and recovery is exact, independent of . | |
| Two phase errors, different blocks | phase syndrome | Uncorrectable: mis-decoded as a block-C flip, recovery completes — a silent logical bit flip, since . |
| Phase-flip degeneracy | : same syndrome, same action | The three intra-block 's share syndrome and act identically on the codespace; the code is degenerate and the ambiguity is harmless. |
| Correlated two-qubit error inside a block | Detected but miscorrected: syndrome matches , recovery gives — beyond the guarantee. |
Worked examples
1 · Correcting a Y error on qubit 5 (fully worked)
A phase-and-bit error strikes the middle qubit of the middle block. Compute the six-bit bit-flip syndrome and the two-bit phase syndrome, and state the recovery.
Step 1. Split the error. is simultaneously a bit flip and a phase flip on qubit 5, so it will trip both the -type and the -type checks. Handle the two parts separately. Y₅ = i·X₅·Z₅.
Step 2. Bit-flip syndrome from the part. Qubit 5 sits in block B, whose checks are and . anticommutes with both (it overlaps each on qubit 5, an odd count), and commutes with all checks in blocks A and C. The six-bit syndrome is therefore . Bit syndrome = (0,0 | 1,1 | 0,0), pinpointing qubit 5.
Step 3. Phase syndrome from the part. overlaps on qubit 5 (odd, anticommute) and on qubit 5 (odd, anticommute), so the two-bit phase syndrome is — the signature of a phase flip on block B. Phase syndrome = (1,1), pinpointing block B.
Step 4. Recover. The bit syndrome within block B uniquely identifies qubit 5, so apply . The phase syndrome identifies block B, so apply a single to that block; by degeneracy all act identically, so choose . The combined recovery inverts up to an irrelevant global phase, restoring the codeword exactly. Recovery = X₅ then Z₅ (any block-B qubit) ≡ Y₅⁻¹ — state restored.
2 · How two errors forge a logical fault
Errors and occur together. Show that the code fails, and identify the resulting logical operation.
Step 1. Bit-flip syndrome. Both are pure errors, which commute with every check, so the entire six-bit bit-flip syndrome is — no bit-flip alarm at all. Bit syndrome = all zeros.
Step 2. Phase syndrome of each error alone. (block A) gives ; (block B) gives . Since Pauli syndromes add mod 2, the combined phase syndrome is . Combined phase syndrome = (0,1).
Step 3. Decoder's mistake. A phase syndrome of is exactly what a single phase flip on block C produces, so a minimum-weight decoder concludes "block C flipped" and applies a to block C — say . It cannot know two errors occurred; has weight-one and weight-two explanations, and it picks the lighter one. Decoder applies Z₇.
Step 4. The net effect. The true errors times the recovery give , a weight-three logical operator. The syndrome is now clean, the decoder believes it succeeded, and the logical qubit has been silently bit-flipped. Net operation = Z₁Z₄Z₇ = X̄ — an undetected logical error, the hallmark of exceeding t = 1.
Physics of the portrait
The Shor code is where a young theorist turned a philosophical worry — that quantum information might be intrinsically unprotectable — into a concrete construction, one year after inventing the factoring algorithm that made protection urgent.
Origins · 1 minPeter Shor and how this was discovered
Peter Williston Shor (born 14 August 1959) was a researcher at AT&T Bell Laboratories when, in 1994, he found the polynomial-time quantum algorithm for factoring integers that made large-scale quantum computing suddenly worth building — and made its fragility suddenly worth solving. Many believed the fragility was fatal: quantum states cannot be cloned, so the classical trick of redundant copies is unavailable, and any measurement to check for errors would collapse the very superposition being protected. In a 1995 paper, "Scheme for reducing decoherence in quantum computer memory" (Phys. Rev. A 52, R2493), Shor dissolved both objections at once. He showed that one can measure stabilizers — joint parities that reveal errors without revealing, or disturbing, the logical state — and that concatenating a phase-flip code with a bit-flip code yields a nine-qubit code correcting an arbitrary single-qubit error. Andrew Steane found a related seven-qubit code independently soon after, and within two years Calderbank, Shor, and Steane had the CSS family, Knill and Laflamme had the general correctability conditions, and Gottesman had the stabilizer formalism that revealed all these codes as one construction. Shor, later the Morss Professor of Applied Mathematics at MIT, received the Nevanlinna Prize, the Gödel Prize, and a MacArthur Fellowship; the nine-qubit code remains the canonical first example through which every student meets quantum error correction.
Going further
Texts. Nielsen and Chuang, Quantum Computation and Quantum Information, §10.2 (Shor code) and §10.3 (discretization) · Preskill, Lecture Notes for Physics 219, Ch. 7 · Watrous, The Theory of Quantum Information, Ch. on error correction · Wilde, Quantum Information Theory, Ch. 24 · Kitaev, Shen and Vyalyi, Classical and Quantum Computation, §15 · Gottesman, Stabilizer Codes and Quantum Error Correction (PhD thesis, 1997). The eight generators mutually commute — every -type overlaps every -type on an even number of qubits — and are independent, giving . The canonical logicals and commute with all stabilizers and anticommute with each other (), reducing to the weight-three representatives and . Distance follows by exhausting all weight- Paulis against the generators (each has nonzero syndrome) and exhibiting those weight-three normalizer elements — noting that is detected, not logical. The worked syndromes are bit and phase , and phase mis-decoded to . The Bacon–Shor trapped-ion result is Egan et al., Nature 598, 281 (2021).
Builds on: Three-Qubit Bit-Flip Code · Three-Qubit Phase-Flip Code · Discretization of Errors · Quantum Error Model and Decoherence Channels · Pauli Group and Clifford Group. Leads to: Stabilizer Formalism · CSS Codes · Steane Seven-Qubit Code · Knill–Laflamme Conditions · Syndrome Measurement and Decoding.
Ask the tutor: name any single-qubit Pauli on qubits 1 through 9 and I will compute its full six-bit and two-bit syndrome, give the recovery, and then show you a two-error pair that slips past the code as a logical fault.
Why does the Shor code need nine qubits when the five-qubit code corrects the same errors?
Because it trades efficiency for transparency. The five-qubit code is the perfect code, saturating the quantum Hamming bound: with it uses the fewest qubits any distance-three code possibly can. The Shor code uses nine because it is built by literally nesting two three-qubit codes, , and that concatenated structure makes everything visible — the -checks are the inner bit-flip votes, the -checks are the outer phase-flip votes, and logical and read off the blocks by eye. The five-qubit code is more compact but its stabilizers mix and on the same qubits and carry no such intuitive story. For learning, and historically, transparency won.
How can you detect an error without measuring — and collapsing — the qubit?
You never measure the qubits; you measure relations between them. Each stabilizer, like , asks "do qubits 1 and 2 agree?" without asking what either value is. Its eigenvalue is on the whole codespace, so measuring it on an uncorrupted codeword returns and leaves the state untouched; an error that flips the agreement returns and reveals that something went wrong without revealing the logical bit. This is the central trick of the entire field: the syndrome lives in the parities, which are unentangled with the logical information, so extracting it disturbs nothing you care about. The logical qubit's superposition survives intact through every round of checking.
What does it mean that the Shor code is degenerate?
Degenerate means distinct errors can share a syndrome and act identically on the codespace, so the decoder need not — and cannot — tell them apart. In the Shor code, a on qubit 1, 2, or 3 all produce the same phase syndrome and all impose the same phase on block A, because they differ only by the stabilizers , which act trivially on codewords. The decoder applies one recovery, say , and it correctly undoes whichever of the three actually happened. Far from a defect, degeneracy is a feature: it lets a code with relatively few stabilizers cover many physical errors, and it is one reason surface codes tolerate such high error rates.
Is the Shor code a CSS code, and why does that matter?
Yes. A CSS (Calderbank–Shor–Steane) code is one whose stabilizers split into a purely -type set and a purely -type set, with no generator mixing the two — and the Shor code's six checks and two weight-six checks do exactly that. This split matters because it decouples the two error types: errors are handled entirely by the -checks and errors entirely by the -checks, so the code is built from two independent classical linear codes, one for each basis. That structure makes CSS codes easy to construct, easy to analyze, and friendly to fault-tolerant gates; the Steane and surface codes are CSS too. The Shor code is the first and most redundant member of the family.
Why is logical X made of Z operators and logical Z made of X operators?
It looks backwards but it is the signature of the concatenation. The outer code is a phase-flip code, whose computational basis is . In that basis, the logical bit-flip — the operation swapping , i.e. — is applied by operators, since swaps . Conversely the logical phase , which distinguishes the two outer states, is read by operators. Concretely places one in each block, and flips one whole block. The apparent role-reversal is just the Hadamard-transformed logic of the outer phase-flip layer showing through.
Does the Shor code protect a qubit indefinitely, or only for one round?
Only for one round of noise between corrections, and only against a single-qubit error within that round. To protect for a long time you repeat the cycle — apply noise, measure the eight stabilizers, decode, recover — many times, and the code keeps the logical error rate low provided at most one physical error accumulates per cycle. If the physical error rate per qubit per cycle is , the logical error rate scales like (two errors needed to cause a logical fault), a suppression only if is small. Fault tolerance then demands that the syndrome extraction itself be built from gadgets that do not spread one error into many; concatenating the code with itself and staying below the threshold is what turns single-round protection into indefinite protection.