The Shor code is a quantum error-correcting code that encodes one logical qubit into nine physical qubits and can correct an arbitrary error on any single qubit. Published by Peter Shor in 1995, it was the first code to show that quantum error correction is possible at all, and it remains the standard teaching example in quantum computing.
The code works by concatenating two three-qubit repetition codes: an outer phase-flip code and an inner bit-flip code. This layered design protects against both bit-flip and phase-flip errors, and because any single-qubit error can be written as a combination of these, it protects against every single-qubit error, including small continuous rotations.
How the Shor code encodes a qubit
The encoding starts with the three-qubit phase-flip code, which maps a logical state into three qubits in the |+⟩ and |−⟩ basis. Each of those three qubits is then encoded again with the three-qubit bit-flip code, producing three blocks of three qubits each, nine qubits in total.
The resulting logical basis states are products of three GHZ-like blocks. The logical zero is the product of three copies of (|000⟩ + |111⟩)/√2, and the logical one is the product of three copies of (|000⟩ − |111⟩)/√2. The relative sign within each block carries the phase information, while the repetition inside a block carries the bit information.
The table below summarizes the two layers of the construction.
| Layer | Code used | Error type corrected | Qubits involved |
|---|---|---|---|
| Inner layer | Three-qubit bit-flip code | X errors within a block | 3 per block |
| Outer layer | Three-qubit phase-flip code | Z errors across blocks | 3 blocks |
| Combined code | Concatenation of both | Any single-qubit error | 9 in total |
In stabilizer notation, the Shor code is written as [[9,1,3]]: nine physical qubits, one logical qubit and a code distance of 3. A distance of 3 means that at least three single-qubit errors are needed to turn one valid codeword into another, so any single error is detectable and correctable.
Syndrome measurement and correction
Errors are found through syndrome measurement, which measures parity checks without revealing the encoded state. The Shor code is a stabilizer code with eight stabilizer generators: six Z-type checks that compare neighboring qubits inside each block and two X-type checks that compare the signs of neighboring blocks.
The following table lists the stabilizer generators and what each one detects.
| Generator type | Example operator | Number | Detects |
|---|---|---|---|
| Z-pair checks | Z₁Z₂, Z₂Z₃ in each block | 6 | Bit flips (X errors) |
| X-block checks | X₁…X₆, X₄…X₉ | 2 | Phase flips (Z errors) |
| Logical X | Z on all nine qubits | 1 | Not a check; logical operator |
| Logical Z | X on all nine qubits | 1 | Not a check; logical operator |
Each syndrome pattern points to a specific correction. A bit flip on qubit 5 makes two Z-pair checks in the middle block disagree, and applying X to qubit 5 restores the state. A phase flip anywhere in a block changes the sign of that block, so the X-block checks identify which block was affected, and applying Z to any qubit of that block fixes it.
An important property is error discretization. A small rotation such as exp(−iεX) is a superposition of no error and an X error, and the syndrome measurement collapses it into one of these cases. Correcting a finite set of Pauli errors therefore handles a continuum of physical errors, a key insight that made quantum error correction workable.
The Shor code compared with other codes
The Shor code is not efficient by modern standards: smaller codes protect one logical qubit against any single-qubit error with fewer resources. Its value lies in its clarity and in its historical role as proof that the obstacles of no-cloning, continuous errors and measurement disturbance can be overcome.
The table compares the Shor code with codes from the same family and with the codes used in current hardware research.
| Code | Parameters | Physical qubits per logical qubit | Notable property |
|---|---|---|---|
| Shor code | [[9,1,3]] | 9 | First code; simple concatenation |
| Steane code | [[7,1,3]] | 7 | Transversal Clifford gates |
| Five-qubit code | [[5,1,3]] | 5 | Smallest code for any single error |
| Surface code | [[d², 1, d]] | d² data qubits | Local checks; high threshold |
| Bacon–Shor code | [[m², 1, m]] subsystem | m² | Generalizes Shor code with gauge qubits |
The Bacon–Shor code extends the idea to larger square grids and treats some stabilizers as gauge operators, which allows measurements of only two-qubit checks. This subsystem version is often studied for hardware because it keeps the simple structure of the Shor code while reducing measurement complexity.
Limitations and role in fault tolerance
The Shor code corrects only one error per codeword. If two qubits fail before correction, the decoder may apply the wrong fix and introduce a logical error. Its usefulness therefore depends on physical error rates being low enough that double errors are rare within one correction cycle.
- High overhead: nine physical qubits per logical qubit, plus ancilla qubits for syndrome extraction.
- Non-local checks: the X-block checks act on six qubits, which is hard on hardware with only nearest-neighbor coupling.
- Weight-six measurements: large stabilizers propagate errors unless measured with fault-tolerant circuits.
- Fixed distance: reaching larger distances requires further concatenation, which multiplies the qubit count.
Concatenation of codes like the Shor code underlies early proofs of the threshold theorem, which states that arbitrarily long computations are possible if physical error rates stay below a threshold. Practical roadmaps now favor surface codes and quantum LDPC codes, but the Shor code remains the conceptual starting point for the whole field.
A non-technical view
Quantum information is fragile. A qubit can be damaged in two ways: its value can flip, or its hidden sign can flip. Ordinary backups do not work, because quantum states cannot be copied.
The Shor code solves this with clever spreading instead of copying. It spreads one qubit across nine. Small checks then compare the pieces without looking at the stored value. If one piece goes wrong, the checks show which piece failed and how. That piece is then repaired. It is like a team of nine guards who check each other, so one mistake never goes unnoticed.
A concrete example
A university laboratory with a trapped-ion processor wants to show students how quantum error correction works on real hardware. The team prepares a logical qubit in the Shor code using nine ions and then deliberately applies a small unwanted rotation to the fifth ion to simulate noise.
Using additional ancilla ions, the team measures the eight stabilizers. The Z-pair checks in the middle block flag qubit 5, and all other checks report no change. Applying the matching correction restores the logical state, and a final decoding step recovers the original qubit with a fidelity clearly above the unprotected case under the same injected error. The demonstration shows the core idea in practice: errors are detected without measuring the data.