Three-Qubit Phase-Flip Code

The three-qubit phase-flip code is the simplest quantum code that protects a qubit against a relative-phase error — the Pauli ZZ that leaves populations untouched and only flips the sign between ∣0⟩|0\rangle and ∣1⟩|1\rangle. Phase errors are the characteristic quantum failure: they have no classical analogue, they are invisible to any measurement in the computational basis, and on most real hardware they are the dominant channel, arriving far faster than energy relaxation. The bit-flip code cannot see them at all. Yet the fix is almost embarrassingly cheap, because ZZ is nothing but a bit flip wearing a disguise: in the conjugate basis {∣+⟩,∣−⟩}\{|+\rangle,|-\rangle\} it obeys Z∣+⟩=∣−⟩Z|+\rangle=|-\rangle, Z∣−⟩=∣+⟩Z|-\rangle=|+\rangle, exactly the algebra of XX in the computational basis. So we do the obvious thing. Rotate the entire error-correcting apparatus of the repetition code into the conjugate basis with a Hadamard on every qubit, run the ordinary majority-vote logic there, and rotate back. Term by term, the bit-flip code maps into the phase-flip code under conjugation by H⊗3H^{\otimes3}: the codewords ∣000⟩,∣111⟩|000\rangle,|111\rangle become ∣+++⟩,∣−−−⟩|{+}{+}{+}\rangle,|{-}{-}{-}\rangle; the checks Z1Z2,Z2Z3Z_1Z_2,Z_2Z_3 become X1X2,X2X3X_1X_2,X_2X_3; and a ZZ error is caught the way an XX error was. This exact duality — swap X↔ZX\leftrightarrow Z and every statement survives — is the cleanest window onto the symplectic symmetry of Pauli noise underneath the whole stabilizer formalism. The code corrects any single phase flip and nothing else; its true importance is that it is one half of Shor's nine-qubit code, the first code to defeat an arbitrary single-qubit error.

Key takeaways
  • The phase-flip code encodes one logical qubit in three as ∣0L⟩=∣+++⟩|0_L\rangle=|{+}{+}{+}\rangle, ∣1L⟩=∣−−−⟩|1_L\rangle=|{-}{-}{-}\rangle, protecting against a single Pauli ZZ (phase) error.
  • It is the exact Hadamard conjugate of the bit-flip code: applying H⊗3H^{\otimes3} carries one code into the other and swaps the roles of XX and ZZ.
  • Its stabilizer group is S=⟨X1X2, X2X3⟩S=\langle X_1X_2,\,X_2X_3\rangle; the two ±1\pm1 syndrome bits locate which qubit was phase-flipped without ever touching the logical amplitudes α,β\alpha,\beta.
  • With code distance d=1d=1 against bit flips it cannot correct a single XX — one XX is a logical operation — so it is only half of a full quantum code.
  • Majority-vote recovery fails at second order, giving logical phase error pL=3p2−2p3≈3p2≪pp_L=3p^2-2p^3\approx3p^2\ll p, a net win for every physical rate p<1/2p<1/2.
  • Key idea: Conjugating the repetition (bit-flip) code by H⊗3H^{\otimes 3} rotates the protected basis into {∣+⟩,∣−⟩}\{|+\rangle,|-\rangle\}, turning ZZ errors into detectable parity violations: ∣0L⟩=∣+++⟩|0_L\rangle=|+++\rangle, ∣1L⟩=∣−−−⟩|1_L\rangle=|---\rangle, with stabilizers X1X2, X2X3X_1X_2,\,X_2X_3.

Where this lives today

The phase-flip code long ago left the textbook and became the working model for the noise that dominates real hardware. Superconducting transmons, semiconductor spin qubits, and many trapped-ion encodings share a stark asymmetry: their dephasing time T2T_2 is far shorter than their relaxation time T1T_1, so phase errors arrive first and fastest, making a phase-protecting repetition code the natural first line of defence. Google Quantum AI's 2021 demonstration of exponential error suppression ran exactly these one-dimensional bit-flip and phase-flip repetition codes, watching the logical error fall as more physical qubits were added; their later surface-code experiments treat the two-basis stabilizer readout as XX-type and ZZ-type checks that are direct descendants of X1X2,X2X3X_1X_2,X_2X_3 and Z1Z2,Z2Z3Z_1Z_2,Z_2Z_3. The idea has also become a design principle for hardware. "Biased-noise" qubits — Kerr-cat and dissipative-cat qubits built from driven superconducting oscillators — are engineered so that bit flips are exponentially suppressed at the physical level, leaving phase flips as essentially the only residual error. For such a qubit a phase-flip repetition code alone suffices for the top layer, and Amazon's 2025 "Ocelot" chip is built around cat qubits protected exactly this way, cutting the overhead of fault tolerance dramatically. The open problem the code still frames is the one Shor posed: how to stay below the fault-tolerance threshold with realistic, biased, correlated noise — where knowing which basis your errors live in is worth more than raw redundancy.

The physical picture

Picture three qubits, each casting a ±\pm vote in the conjugate basis. The logical information is carried by the common sign pattern — all-plus is ∣0L⟩|0_L\rangle, all-minus is ∣1L⟩|1_L\rangle — while a superposition α∣0L⟩+β∣1L⟩\alpha|0_L\rangle+\beta|1_L\rangle keeps the two patterns coherently overlaid. A single ZZ error flips exactly one vote, breaking the unanimity. Error correction must detect the disagreement without ever asking any qubit for its absolute vote, which would collapse the superposition and destroy α,β\alpha,\beta. Measuring the relative signs of neighbouring pairs — the XX-parities X1X2X_1X_2 and X2X3X_2X_3 — does exactly this: each returns +1+1 if its pair agrees and −1-1 if it disagrees, pinning down the odd one out while learning nothing about the shared value. The first figure follows this through the encoder that prepares the votes.

Figure
Encoding circuit: two CNOTs spread α|0⟩ + β|1⟩ into the bit-flip codewords, then a Hadamard on every qubit rotates into the conjugate basis to give α|+++⟩ + β|−−−⟩; because H X H = Z the whole code is the repetition code conjugated by H⊗3, so a phase flip Z acts as an ordinary bit flip in the ± basis
Phase-flip encoder — repetition code conjugated by H⊗3 α|0⟩ + β|1⟩ |0⟩ |0⟩ two CNOTs: bit-flip encoder H H H rotate to ± basis α|+++⟩ + β|−−−⟩ Z|+⟩ = |−⟩ → a phase flip is a bit flip among the votes

The whole code is the bit-flip code seen through a Hadamard lens, and it corrects only ZZ. That makes it half of a complete scheme: stack it on top of the bit-flip code — so each ±\pm vote is itself a bit-flip-protected triple — and the remaining XX gap closes. That two-layer stack is precisely Shor's nine-qubit code. But "cheap protection" is only worth having if it actually lowers the error rate, and it does so only up to a point. The second figure is the ledger every code must satisfy: the encoded logical error pL=3p2−2p3p_L=3p^2-2p^3 against the bare physical rate pp, showing the quadratic suppression at small pp and the break-even crossing where redundancy stops helping.

Figure
The break-even ledger: encoded logical phase error p_L = 3p² − 2p³ versus the bare physical rate p; the encoded curve sits below the diagonal for every p below 1/2, giving p_L = 0.00725 at p = 0.05 (a 6.9-fold reduction), and the two meet exactly at the threshold p = 1/2 where encoding stops paying
When encoding pays: p_L = 3p² − 2p³ vs the bare rate p, break-even at p = 1/2 0.1 0.2 0.3 0.4 0.5 0.1 0.2 0.3 0.4 0.5 physical phase-flip rate p logical error p_L unencoded p_L = p encoded 3p² − 2p³ p = 0.05 → 0.00725 break-even (0.5, 0.5)

The core equations

The two logical codewords are the all-plus and all-minus strings in the conjugate basis. They are the images of the bit-flip codewords ∣000⟩,∣111⟩|000\rangle,|111\rangle under a Hadamard on every qubit, and they span the two-dimensional code space in which one logical qubit lives.

∣0L⟩=∣+++⟩,∣1L⟩=∣−−−⟩(1)|0_L\rangle = |{+}{+}{+}\rangle,\qquad |1_L\rangle = |{-}{-}{-}\rangle \qquad (1)

where: ∣±⟩=12(∣0⟩±∣1⟩)|\pm\rangle=\tfrac{1}{\sqrt2}(|0\rangle\pm|1\rangle) — the eigenstates of XX with eigenvalue ±1\pm1; ∣0L⟩,∣1L⟩|0_L\rangle,|1_L\rangle — the logical basis of the encoded qubit. Reading: the two codewords are the ±1\pm1 eigenstates of X⊗3X^{\otimes3}, maximally spread over the Hadamard basis rather than the computational one. Encoding is a coherent map, not a copy. An arbitrary input qubit is carried into the code space with its amplitudes intact — no-cloning is respected because what is triplicated is the basis, not the unknown numbers α,β\alpha,\beta.

α∣0⟩+β∣1⟩  ⟼  α∣+++⟩+β∣−−−⟩(2)\alpha|0\rangle+\beta|1\rangle \;\longmapsto\; \alpha|{+}{+}{+}\rangle+\beta|{-}{-}{-}\rangle \qquad (2)

where: α,β\alpha,\beta — input amplitudes with ∣α∣2+∣β∣2=1|\alpha|^2+|\beta|^2=1. Reading: the superposition is preserved and delocalized; measuring any single qubit would project it and destroy the encoded state, which is exactly why recovery must use stabilizers instead. The stabilizer group is the set of Pauli operators that fix every codeword. Its two generators are XX-type parity checks — the conjugate-basis analogue of the bit-flip code's ZZ-type checks.

S=⟨ X1X2,  X2X3 ⟩(3)S = \langle\, X_1X_2,\; X_2X_3 \,\rangle \qquad (3)

where: XiXjX_iX_j — Pauli XX on qubits i,ji,j and identity elsewhere, a parity check in the ±\pm basis; SS — the abelian group with S∣ψL⟩=+∣ψL⟩S|\psi_L\rangle=+|\psi_L\rangle for every stabilizer SS and codeword ∣ψL⟩|\psi_L\rangle. Reading: both generators return +1+1 on any codeword because each pair of votes agrees; an error that disagrees with a generator flips its sign to −1-1. The logical operators act within the code space, mapping codewords to codewords. They commute with every stabilizer but lie outside SS, and they anticommute with each other as a logical Pauli pair must.

Xˉ=Z1Z2Z3,Zˉ=X1 (≡X2≡X3  S)(4)\bar X = Z_1Z_2Z_3,\qquad \bar Z = X_1\ (\equiv X_2 \equiv X_3 \bmod S) \qquad (4)

where: Xˉ\bar X — the logical bit flip, ∣+++⟩↔∣−−−⟩|{+}{+}{+}\rangle\leftrightarrow|{-}{-}{-}\rangle; Zˉ\bar Z — the logical phase flip, realized by any single XiX_i up to a stabilizer. Reading: note the reversal — a single physical XiX_i is the logical Zˉ\bar Z, which is why one bit flip is uncorrectable and the distance against XX noise is d=1d=1. The entire construction is fixed by one line of Clifford algebra: the Hadamard swaps XX and ZZ by conjugation. This is the exact map from the bit-flip code, and every feature of this code is the X↔ZX\leftrightarrow Z image of a bit-flip feature.

Uphase=H⊗3 Ubit,HXH=Z,HZH=X(5)U_{\text{phase}} = H^{\otimes 3}\, U_{\text{bit}},\qquad H X H = Z,\quad H Z H = X \qquad (5)

where: UbitU_{\text{bit}} — the bit-flip encoder (two CNOTs from qubit 1 onto 2 and 3); H⊗3H^{\otimes3} — a Hadamard on each qubit. Reading: conjugation is an isomorphism of the whole apparatus, so codewords, stabilizers, syndromes, and distance all transport under X↔ZX\leftrightarrow Z with no independent work. Error detection measures the two generators, returning a two-bit syndrome. Each ZiZ_i anticommutes with exactly those generators that overlap it on a single site, so the syndrome is a distinct nonzero fingerprint for each single-qubit phase flip.

s1=⟨X1X2⟩,s2=⟨X2X3⟩:errors1s2I++Z1−+Z2−−Z3+−(6)s_1=\langle X_1X_2\rangle,\quad s_2=\langle X_2X_3\rangle:\qquad \begin{array}{c|cc} \text{error} & s_1 & s_2 \\\hline I & + & + \\ Z_1 & - & + \\ Z_2 & - & - \\ Z_3 & + & - \end{array} \qquad (6)

where: s1,s2s_1,s_2 — the ±1\pm1 outcomes of the two stabilizer measurements; ZiZ_i — a phase flip on qubit ii. Reading: the four cases {I,Z1,Z2,Z3}\{I,Z_1,Z_2,Z_3\} map to four distinct syndromes, so a lone phase flip is always located and undone by re-applying ZiZ_i. Finally, with independent per-qubit phase flips the majority-vote decoder fails only when two or three qubits flip. Summing those events gives the logical error rate, quadratically smaller than the physical rate at low pp.

pL=3p2(1−p)+p3=3p2−2p3(7)p_L = 3p^2(1-p) + p^3 = 3p^2 - 2p^3 \qquad (7)

where: pp — per-qubit phase-flip probability; pLp_L — probability the decoder yields a residual logical Zˉ\bar Z. Reading: for small pp, pL≈3p2≪pp_L\approx3p^2\ll p, and encoding wins whenever 3p2−2p3<p3p^2-2p^3<p, i.e. for all p<1/2p<1/2.

Derivation ABuilding the phase-flip code by Hadamard conjugation

The goal here is to earn every ingredient of the code — codewords, stabilizers, detectable error, and logical operators — from a single structural fact rather than separate assertions: that the phase-flip code is the exact image of the bit-flip repetition code under a transversal Hadamard H⊗3H^{\otimes3}. Because conjugation by a unitary preserves all commutation relations, eigenvalue equations, and group structure, we may transport the entire already-understood bit-flip apparatus across the map, and the X↔ZX\leftrightarrow Z swap it induces does the rest.

Step 1. Fix the single-qubit action from H∣0⟩=∣+⟩H|0\rangle=|+\rangle, H∣1⟩=∣−⟩H|1\rangle=|-\rangle, and the involutions HXH=ZHXH=Z, HZH=XHZH=X, H2=IH^2=I. Apply H⊗3H^{\otimes3} to the bit-flip codewords: H⊗3∣000⟩=∣+++⟩H^{\otimes3}|000\rangle=|{+}{+}{+}\rangle and H⊗3∣111⟩=∣−−−⟩H^{\otimes3}|111\rangle=|{-}{-}{-}\rangle, so the encoding map α∣000⟩+β∣111⟩↦α∣+++⟩+β∣−−−⟩\alpha|000\rangle+\beta|111\rangle\mapsto\alpha|{+}{+}{+}\rangle+\beta|{-}{-}{-}\rangle is nothing but conjugating the bit-flip encoder. Why: this pins the code space as the Hadamard image of the repetition space, and confirms equations (1) and (2) without any new postulate.

Step 2. Transport the stabilizers. The bit-flip generators are Z1Z2,Z2Z3Z_1Z_2,Z_2Z_3; conjugating each factor, H⊗3(ZiZj)H⊗3=(HZH)i(HZH)j=XiXjH^{\otimes3}(Z_iZ_j)H^{\otimes3}=(HZH)_i(HZH)_j=X_iX_j. Hence ⟨Z1Z2,Z2Z3⟩→⟨X1X2,X2X3⟩\langle Z_1Z_2,Z_2Z_3\rangle\to\langle X_1X_2,X_2X_3\rangle, which is equation (3). Why: because conjugation preserves the property "fixes every codeword," the images are automatically the stabilizers of the image code — no recomputation of eigenvalues needed.

Step 3. Transport the error being corrected. The bit-flip code detects a physical XiX_i; its image is H⊗3XiH⊗3=ZiH^{\otimes3}X_iH^{\otimes3}=Z_i. So the detectable error becomes the phase flip ZiZ_i, and — reading the map the other way — a physical ZZ in the old code becomes a physical XX in the new one, now undetectable. Why: this single substitution is the whole content of the duality, and it explains simultaneously why the code sees ZZ and is blind to XX.

Step 4. Get the logical operators and the distance. Transporting the bit-flip logicals Xˉbit=X1X2X3\bar X_{\text{bit}}=X_1X_2X_3 and Zˉbit=Z1\bar Z_{\text{bit}}=Z_1 gives Xˉ=Z1Z2Z3\bar X=Z_1Z_2Z_3 and Zˉ=X1\bar Z=X_1. Check independently: Xˉ=Z1Z2Z3\bar X=Z_1Z_2Z_3 overlaps each XiXjX_iX_j on two sites (even), so it commutes with SS; and Z1Z2Z3∣+++⟩=∣−−−⟩Z_1Z_2Z_3|{+}{+}{+}\rangle=|{-}{-}{-}\rangle, so it swaps the codewords. Meanwhile X1∣+++⟩=+∣+++⟩X_1|{+}{+}{+}\rangle=+|{+}{+}{+}\rangle and X1∣−−−⟩=−∣−−−⟩X_1|{-}{-}{-}\rangle=-|{-}{-}{-}\rangle, so Zˉ=X1\bar Z=X_1; it shares one site with Xˉ\bar X and so anticommutes with it. Why: because Zˉ\bar Z is a weight-one operator, a single physical bit flip already implements a logical operation, proving the distance against XX noise is d=1d=1 — the code's fundamental limitation, extracted for free from the map.

Go deeper · Derivation B · 1 minCorrecting a single phase flip on qubit two
Derivation BCorrecting a single phase flip on qubit two

The goal is to trace a completely general encoded state through the full cycle — error, syndrome extraction, recovery — and verify that the original amplitudes emerge untouched, seeing explicitly how the measurement learns the error location while staying ignorant of the logical data. The subtlety to watch is that both branches of the superposition must yield the same syndrome outcome deterministically; otherwise the measurement would collapse α,β\alpha,\beta and corrupt the qubit even as it "corrected" it.

Step 1. Apply the error to ∣ψL⟩=α∣+++⟩+β∣−−−⟩|\psi_L\rangle=\alpha|{+}{+}{+}\rangle+\beta|{-}{-}{-}\rangle. Since Z∣+⟩=∣−⟩Z|+\rangle=|-\rangle and Z∣−⟩=∣+⟩Z|-\rangle=|+\rangle, the operator Z2Z_2 flips only the middle label: ∣ψ′⟩=α∣+−+⟩+β∣−+−⟩|\psi'\rangle=\alpha|{+}{-}{+}\rangle+\beta|{-}{+}{-}\rangle. Why: this is the entire physical effect of a phase flip written in the conjugate basis, where it looks like a single flipped vote.

Step 2. Measure X1X2X_1X_2. Using X∣±⟩=±∣±⟩X|\pm\rangle=\pm|\pm\rangle: on ∣+−+⟩|{+}{-}{+}\rangle the eigenvalues are (+1)(−1)=−1(+1)(-1)=-1, and on ∣−+−⟩|{-}{+}{-}\rangle they are (−1)(+1)=−1(-1)(+1)=-1. Both branches give s1=−1s_1=-1, so the outcome is deterministic and no superposition collapses. Why: the stabilizer commutes with the logical content, so it can only report the error, never the value of α,β\alpha,\beta.

Step 3. Measure X2X3X_2X_3. On ∣+−+⟩|{+}{-}{+}\rangle: (−1)(+1)=−1(-1)(+1)=-1; on ∣−+−⟩|{-}{+}{-}\rangle: (+1)(−1)=−1(+1)(-1)=-1. So s2=−1s_2=-1, again deterministically, and the syndrome (s1,s2)=(−,−)(s_1,s_2)=(-,-) uniquely fingerprints a Z2Z_2 error by the table in equation (6). Why: only Z2Z_2 overlaps both generators on a single site, so only Z2Z_2 anticommutes with both — the fingerprint is unambiguous.

Step 4. Recover by re-applying the indicated operator: Z2∣ψ′⟩=α∣+++⟩+β∣−−−⟩=∣ψL⟩Z_2|\psi'\rangle=\alpha|{+}{+}{+}\rangle+\beta|{-}{-}{-}\rangle=|\psi_L\rangle. The state is restored exactly, and at no point were α\alpha or β\beta measured. Why: since Z22=IZ_2^2=I, undoing a known Pauli is exact and unitary, completing a full error-correction cycle with the logical information intact.

Go deeper · Derivation C · 1 minThe logical error rate and the break-even threshold
Derivation CThe logical error rate and the break-even threshold

The goal is to compute precisely when the code helps rather than harms, by counting the noise configurations the majority-vote decoder gets wrong, summing their probabilities, and comparing to the unencoded rate pp. The decoder assumes at most one flip and applies the correction a single flip would demand; the interesting content is the events where that assumption is false, and the payoff is a clean quadratic suppression with a sharply defined break-even point.

Step 1. Enumerate the failure events. With zero or one phase flip the syndrome points to the true error (or to none) and recovery succeeds. With two flips, the syndrome instead matches the single un-flipped qubit, so the decoder "corrects" that one — turning two flips into three, which is the logical Zˉ=Z1Z2Z3\bar Z=Z_1Z_2Z_3. With three flips the state is already Zˉ∣ψL⟩\bar Z|\psi_L\rangle. Both the two-flip and three-flip cases are logical errors. Why: the decoder is a majority vote, and a majority-vote code with three copies is overwhelmed exactly when the minority is no longer a minority.

Step 2. Sum the two-flip probability. There are (32)=3\binom{3}{2}=3 ways to place two flips, each with probability p2(1−p)p^2(1-p), giving 3p2(1−p)3p^2(1-p). Why: independence lets the joint probability factor, and the binomial coefficient counts the equivalent placements.

Step 3. Add the three-flip probability, (33)p3=p3\binom{3}{3}p^3=p^3. Combining, pL=3p2(1−p)+p3=3p2−3p3+p3=3p2−2p3p_L=3p^2(1-p)+p^3=3p^2-3p^3+p^3=3p^2-2p^3, confirming equation (7). Why: these are the only remaining error weights, so their sum is the total logical failure probability.

Step 4. Locate the break-even point. Encoding helps when pL<pp_L<p, i.e. 3p2−2p3<p3p^2-2p^3<p, i.e. 2p2−3p+1>02p^2-3p+1>0, i.e. (2p−1)(p−1)>0(2p-1)(p-1)>0. For 0<p<10<p<1 this holds precisely when p<1/2p<1/2. At p=0.05p=0.05 the code gives pL=3(0.0025)−2(0.000125)=0.00725p_L=3(0.0025)-2(0.000125)=0.00725, a 6.96.9-fold reduction; at the threshold p=1/2p=1/2 both rates equal 0.50.5. Why: the break-even at p=1/2p=1/2 is identical to the bit-flip code's, exactly as the Hadamard duality demands — the two codes are the same code in different bases.

Limiting cases

How the code behaves as the noise channel and the physical rate are varied:

CaseResultMeaning
Single ZZ errorZi, i∈{1,2,3}Z_i,\ i\in\{1,2,3\}Fully correctable — each location gives a distinct nonzero syndrome and re-applying ZiZ_i restores the state exactly.
Single XX errorXiX_iUndetectable — XiX_i commutes with both generators, gives syndrome (+,+)(+,+), and acts as the logical Zˉ\bar Z; distance against bit flips is d=1d=1.
Low phase-flip ratepL≈3p2p_L\approx3p^2Quadratic suppression; encoding beats the bare rate pp for all p<1/2p<1/2, with the largest relative gain as p→0p\to0.
Continuous dephasingRz(θ)=cos⁡θ2 I−isin⁡θ2 ZR_z(\theta)=\cos\tfrac\theta2\,I-i\sin\tfrac\theta2\,ZSyndrome measurement digitizes it — the state collapses onto II (no error) or ZiZ_i (correctable) with the right probabilities.
Depolarizing noiseE(ρ)=(1−p)ρ+p3(XρX+YρY+ZρZ)\mathcal E(\rho)=(1-p)\rho+\tfrac p3(X\rho X+Y\rho Y+Z\rho Z)Worse than doing nothing — the XX and YY parts are uncorrected, so only a phase-biased channel benefits.

Worked examples

1 · A full correction cycle on a phase-flipped superposition (fully worked)

An encoded state ∣ψL⟩=12∣+++⟩+12∣−−−⟩|\psi_L\rangle=\tfrac{1}{\sqrt2}|{+}{+}{+}\rangle+\tfrac{1}{\sqrt2}|{-}{-}{-}\rangle (that is, α=β=1/2\alpha=\beta=1/\sqrt2) suffers a phase flip on qubit 3. Work out the corrupted state, both syndrome bits, the decoded location, and confirm exact recovery.

Step 1. Apply the error. Z3Z_3 flips the third label of each branch: ∣ψ′⟩=12∣++−⟩+12∣−−+⟩|\psi'\rangle=\tfrac{1}{\sqrt2}|{+}{+}{-}\rangle+\tfrac{1}{\sqrt2}|{-}{-}{+}\rangle. The logical amplitudes are still 1/21/\sqrt2 each — the error has not touched them, only the sign pattern.

Step 2. Measure X1X2X_1X_2. On ∣++−⟩|{+}{+}{-}\rangle the first two eigenvalues are (+1)(+1)=+1(+1)(+1)=+1; on ∣−−+⟩|{-}{-}{+}\rangle they are (−1)(−1)=+1(-1)(-1)=+1. Both branches agree, so s1=+1s_1=+1.

Step 3. Measure X2X3X_2X_3. On ∣++−⟩|{+}{+}{-}\rangle: (+1)(−1)=−1(+1)(-1)=-1; on ∣−−+⟩|{-}{-}{+}\rangle: (−1)(+1)=−1(-1)(+1)=-1. Both agree, so s2=−1s_2=-1. The syndrome is (+,−)(+,-).

Step 4. Decode. From the table in equation (6), (+,−)(+,-) is the unique fingerprint of Z3Z_3. Apply Z3Z_3: Z3∣ψ′⟩=12∣+++⟩+12∣−−−⟩=∣ψL⟩Z_3|\psi'\rangle=\tfrac{1}{\sqrt2}|{+}{+}{+}\rangle+\tfrac{1}{\sqrt2}|{-}{-}{-}\rangle=|\psi_L\rangle. The state is recovered exactly, and the balanced superposition α=β=1/2\alpha=\beta=1/\sqrt2 was never disturbed — both branches returned identical syndrome bits, so the logical information survived the measurement untouched.

2 · Is encoding worth it at p=0.10p=0.10?

Independent phase flips strike each physical qubit with probability p=0.10p=0.10. Compute the logical error, compare to the unencoded qubit, and state the margin to break-even.

Step 1. Unencoded, a lone qubit fails with probability p=0.10p=0.10.

Step 2. Encoded, from equation (7): pL=3p2−2p3=3(0.01)−2(0.001)=0.030−0.002=0.028p_L=3p^2-2p^3=3(0.01)-2(0.001)=0.030-0.002=\mathbf{0.028}.

Step 3. The ratio is 0.10/0.028≈3.60.10/0.028\approx\mathbf{3.6}: encoding cuts the error roughly 3.63.6-fold. Since 0.10<1/20.10<1/2 we are comfortably on the winning side of the threshold; the margin shrinks as pp climbs toward 1/21/2, where the advantage vanishes. At p=0.10p=0.10 the phase-flip code lowers the logical error from 0.100.10 to 0.0280.028.

Physics of the portrait

The phase-flip code has no single "discoverer" the way a natural constant does, but it entered the world inside one landmark paper. In 1995 Peter Shor showed that a qubit could be shielded from decoherence at all — and the phase-flip repetition code is the piece of his construction that handles the uniquely quantum half of the problem.

Origins · 1 minPeter Shor and how this was discovered
PS
Peter Shor
b. 1959 · quantum error correction and the nine-qubit code

Peter Williston Shor is the applied mathematician whose 1994 factoring algorithm turned quantum computing from a curiosity into a threat to modern cryptography — and who, one year later, supplied the antidote. The immediate objection to his own algorithm was that any real quantum computer would decohere long before finishing: a qubit in superposition seemed impossible to protect, because measuring it to check for errors would destroy the superposition, and the no-cloning theorem forbade the classical trick of keeping backup copies. Shor's 1995 paper, "Scheme for reducing decoherence in quantum computer memory," broke this impasse. His insight was to spread one logical qubit across nine physical qubits in two nested layers: an inner three-qubit repetition code against bit flips, wrapped in an outer three-qubit code — the phase-flip code — against phase flips, the outer layer obtained by conjugating the inner code with Hadamards so that ZZ errors become detectable in the {∣+⟩,∣−⟩}\{|+\rangle,|-\rangle\} basis. Syndrome measurements read out which error occurred without ever reading the logical data, and by discretization the scheme corrects any continuous single-qubit disturbance, not just XX, YY, ZZ. Shor's nine-qubit code was the existence proof the field needed; the three-qubit phase-flip code is the conceptually decisive half of it, isolating the purely quantum error that has no classical shadow.

History
1994
— Shor's factoring algorithm makes fault-tolerant quantum memory an urgent open problem
1995
— Shor publishes the nine-qubit code, embedding the phase-flip repetition code as its outer layer
1996
— Steane's seven-qubit code and the Calderbank-Shor-Steane construction unify X-type and Z-type checks
1996
— Knill and Laflamme give the general quantum error-correction conditions
1997
— Gottesman's stabilizer formalism recasts the code as the group generated by X1X2 and X2X3
1998
— Cory and co-workers demonstrate three-qubit error correction in a nuclear-spin experiment

Going further

Texts. Nielsen & Chuang, Quantum Computation and Quantum Information, §10.1.2 (the three-qubit codes) · Preskill, Lecture Notes for Physics 219, Ch. 7 · Gottesman, Stabilizer Codes and Quantum Error Correction (PhD thesis, 1997) · Mermin, Quantum Computer Science, Ch. 5 · Kitaev, Shen, Vyalyi, Classical and Quantum Computation, Ch. 14 · Lidar & Brun (eds.), Quantum Error Correction, Ch. 2. The code first appears as the outer layer of Shor's 1995 nine-qubit construction (Phys. Rev. A 52, R2493). Key consistency checks: (i) H∣0⟩=∣+⟩H|0\rangle=|+\rangle, H∣1⟩=∣−⟩H|1\rangle=|-\rangle and HZH=XHZH=X confirm the encoding map and stabilizer images; (ii) the syndrome table follows from evaluating XiXjX_iX_j eigenvalues on ZkZ_k-corrupted codewords via X∣±⟩=±∣±⟩X|\pm\rangle=\pm|\pm\rangle; (iii) pL=3p2−2p3p_L=3p^2-2p^3 follows from (32)=3\binom{3}{2}=3 and (33)=1\binom{3}{3}=1, with break-even condition (2p−1)(p−1)>0⇒p<1/2(2p-1)(p-1)>0\Rightarrow p<1/2; (iv) Xˉ=Z1Z2Z3\bar X=Z_1Z_2Z_3 commutes with both generators by even overlap, and anticommutes with Zˉ=X1\bar Z=X_1.

Prerequisites. Three-Qubit Bit-Flip Code · Pauli Group and Clifford Group · Quantum Error Model and Decoherence Channels · Stabilizer Formalism. Leads to. Shor Nine-Qubit Code · Discretization of Errors · CSS Codes · Syndrome Measurement and Decoding.

Ask the tutor: Ask me to walk a corrupted codeword through the full syndrome table, or to nest this code inside the bit-flip code and watch Shor's nine-qubit code emerge layer by layer.

Why does a phase flip need a special code at all — isn't it just another bit error?

A phase flip is genuinely new physics with no classical counterpart, which is why it needs its own machinery. Classically a bit is 0 or 1 and the only failure is a flip; there is no "sign between 0 and 1" to corrupt. A qubit carries a relative phase in superpositions like α∣0⟩+β∣1⟩\alpha|0\rangle+\beta|1\rangle, and a ZZ error sends this to α∣0⟩−β∣1⟩\alpha|0\rangle-\beta|1\rangle — the populations ∣α∣2,∣β∣2|\alpha|^2,|\beta|^2 are unchanged, so no measurement in the computational basis can see it, and the bit-flip code is completely blind. The phase-flip code exists to catch this uniquely quantum error, by rotating into the basis where it does look like an ordinary flip.

How can measuring the qubits to find the error not destroy the superposition?

The measurements are chosen to commute with the logical information. We never measure a single qubit's value; we measure the joint observables X1X2X_1X_2 and X2X3X_2X_3, which ask only "do these two votes agree?" and are silent about the shared value. On any codeword both branches of a superposition return the identical syndrome bit, so the outcome is deterministic and carries no information about α\alpha or β\beta. A measurement that always yields the same result regardless of the logical state cannot collapse it. That is the central design rule of every stabilizer code: extract the error, not the data.

Why exactly is the code helpless against a single bit flip?

Because a bit flip XiX_i commutes with every stabilizer generator — the generators are themselves products of XX operators, and Paulis of the same type always commute. Commuting with all stabilizers means XiX_i gives the trivial syndrome (+,+)(+,+), so the code sees nothing. And XiX_i is not harmless: on the codewords it multiplies the ∣−−−⟩|{-}{-}{-}\rangle branch by −1-1 while fixing ∣+++⟩|{+}{+}{+}\rangle, exactly the action of the logical Zˉ\bar Z. So a single bit flip silently applies a logical phase error. Its weight-one nature makes the distance against XX noise equal to one; only nesting the code inside a bit-flip code raises it.

What does "distance one against X errors" actually mean here?

Code distance is the weight of the smallest error that acts as a nontrivial logical operation while being undetectable. For phase (ZZ) errors this code has distance three: you need all three qubits flipped to reach the logical Xˉ=Z1Z2Z3\bar X=Z_1Z_2Z_3, so any single or double ZZ is caught. But for bit (XX) errors the logical operator Zˉ=X1\bar Z=X_1 has weight one — a single physical bit flip already is a logical operation and triggers no syndrome. So the distance against XX noise is d=1d=1, the minimum possible, meaning zero protection. A code's distance is really a per-error-type statement, and this asymmetry, d=3d=3 for phase, d=1d=1 for bit, is the precise sense in which the code is "half" of a real one.

How does concatenating with the bit-flip code give the Shor code?

You build it in two layers. Start with the phase-flip code: one logical qubit becomes α∣+++⟩+β∣−−−⟩\alpha|{+}{+}{+}\rangle+\beta|{-}{-}{-}\rangle on three qubits, immune to phase flips. Now each of those three qubits is itself fragile to bit flips, so replace each one with a bit-flip-encoded triple, ∣+⟩→12(∣000⟩+∣111⟩)|+\rangle\to\tfrac1{\sqrt2}(|000\rangle+|111\rangle) and ∣−⟩→12(∣000⟩−∣111⟩)|-\rangle\to\tfrac1{\sqrt2}(|000\rangle-|111\rangle). Three blocks of three qubits gives nine physical qubits. The inner bit-flip layers correct any single XX, the outer phase-flip layer corrects any single ZZ, a Y=iXZY=iXZ is handled as one of each, and by discretization any continuous single-qubit error is corrected too. That nested construction is exactly Shor's 1995 nine-qubit code — the phase-flip code supplying the outer, quantum-specific layer.

Does the phase-flip code matter on real hardware or is it only pedagogy?

It is both, and the practical side is growing. Many leading qubits — superconducting transmons, spin qubits, some ion encodings — dephase much faster than they relax (T2≪T1T_2\ll T_1), so phase flips are the dominant error and a phase-protecting code targets the real bottleneck. Google's repetition-code experiments used one-dimensional phase-flip (and bit-flip) codes as their first hardware demonstrations of error suppression scaling with qubit number. More strikingly, "cat qubit" hardware is deliberately engineered so bit flips are exponentially rare, leaving phase flips as almost the only error — for which a phase-flip repetition code is the natural and sufficient outer code, as in Amazon's Ocelot chip. Knowing which basis your noise lives in, the whole lesson of this code, translates directly into lower qubit overhead.

Before this

Where this leads