Back to Curriculum
Noise & Error Correction Recommended

Quantum Error-Correcting Codes

Encoding one logical qubit across many physical qubits without measuring its state

By the end of this topic you'll be able to

Explain how the 3-qubit bit-flip code detects and corrects an error using syndrome measurement
Explain why protecting against both bit flips and phase flips needs more machinery (Shor's 9-qubit code)
State what a [[n,k,d]] code's three parameters mean

Preskill's lecture notes frame a quantum error-correcting code (QECC) precisely: a mapping of k logical, or encoded, qubits into a larger space of n physical qubits, where n>k, with the extra n−k qubits storing the k logical qubits redundantly enough that the encoded information is not easily damaged.

The classic worked example is Shor's own 9-qubit code, with n=9 and k=1. Its two basis states, the logical |0̄⟩ and logical |1̄⟩, are each a 3-qubit 'cat' state (|000⟩+|111⟩)/√2 (with the second sign flipped for |1̄⟩), repeated three times over — and crucially, no measurement of any one or two qubits in the block reveals anything about which logical state is encoded, because the information is written nonlocally, in the entanglement among all nine qubits.

Consider first just one of those three 3-qubit clusters protecting against a single bit flip. If a bit-flip error strikes one of its three physical qubits, Preskill shows that measuring two syndrome operators, Z₁Z₂ and Z₂Z₃, is enough to locate it: the eigenvalues of these operators change in a pattern that identifies exactly which qubit disagrees with the other two, without ever revealing the logical amplitudes α or β.

qubit 1

qubit 2

qubit 3

Z₁Z₂ agreeZ₂Z₃ agree

No error detected — click a qubit above to simulate a bit-flip error hitting it.

Crucially, this diagnostic measurement must be collective — you learn the value of Z₁Z₂ as a joint property of two qubits, never the separate values of Z₁ and Z₂ individually, since learning those separately would collapse exactly the superposition being protected. In practice this collective measurement is carried out with an ancilla qubit and a pair of controlled-NOT gates, exactly the construction introduced in the Circuits & Gates track.

A 3-qubit cluster like this suffices against bit flips alone, but it does nothing against phase flips, and Shor's construction repeats the cluster three times over specifically to close that gap: an outer layer of three clusters, checked against relative phase flips via six-qubit observables such as X₁X₂X₃X₄X₅X₆, catches phase errors the same way the inner clusters catch bit flips.

Preskill works out the resulting reliability concretely: if each of the nine qubits independently suffers a bit flip or phase flip with probability p, the probability that the logical qubit ends up damaged is bounded above by roughly 16p² — an improvement over the unprotected error rate p whenever p is smaller than about 1/16, at the cost of nine physical qubits standing in for one logical qubit.

Codes of this kind are labeled with three parameters, [[n,k,d]]: n physical qubits, k logical qubits, and a distance d equal to the minimum number of physical errors needed to cause an undetectable logical error, which sets how many errors the code can correct: ⌊(d−1)/2⌋. Shor's code is [[9,1,3]]; the Steane code, taken up alongside the stabilizer formalism next, reaches the same [[7,1,3]] protection using only seven physical qubits rather than nine.

Try It Yourself

Worked Example

The bit-flip code encodes α|000⟩+β|111⟩. Suppose a bit flip strikes the middle qubit, producing α|010⟩+β|101⟩. Compute the Z₁Z₂ and Z₂Z₃ syndrome eigenvalues for both terms and confirm they agree (so the superposition survives the measurement).

  1. 1Zᵢ has eigenvalue +1 on |0⟩ and −1 on |1⟩, so ZᵢZⱼ on a definite bit string has eigenvalue +1 if bits i,j match, and −1 if they differ.
  2. 2For |010⟩ (bits: q1=0, q2=1, q3=0): Z₁Z₂ compares q1,q2 (0 vs 1, differ) → −1. Z₂Z₃ compares q2,q3 (1 vs 0, differ) → −1.
  3. 3For |101⟩ (bits: q1=1, q2=0, q3=1): Z₁Z₂ compares q1,q2 (1 vs 0, differ) → −1. Z₂Z₃ compares q2,q3 (0 vs 1, differ) → −1.
  4. 4Both terms give exactly the same syndrome, (Z₁Z₂, Z₂Z₃) = (−1, −1) — this agreement is exactly what allows the measurement to reveal the error location without collapsing or revealing anything about α and β.
Answer

Both branches give syndrome (−1, −1), which — as the derivation below tabulates — uniquely identifies 'qubit 2 flipped' among the four possible cases (no error, or a flip on qubit 1, 2, or 3).

Reference

Bit-flip code3-qubit code, protects against X errors only
Syndrome measurementReveals which qubit disagrees, without revealing α, β
Shor code9 physical qubits, 1 logical qubit, protects against any single-qubit error
[[n,k,d]] notationCorrects up to ⌊(d−1)/2⌋ errors

Quick Check

What do the syndrome measurements Z₁Z₂ and Z₂Z₃ reveal in the 3-qubit bit-flip code?

Why does the Shor code need 9 physical qubits rather than just 3?

Ready to move on?