Note: Company names, engineers, incidents, numbers, and scaling scenarios in this article are hypothetical — even when they resemble real ones. See the full disclaimer.

In short

The 3-qubit phase-flip code is the bit-flip code rotated into the X basis. The encoding is |0\rangle_L = |+++\rangle and |1\rangle_L = |---\rangle, where |\pm\rangle = (|0\rangle \pm |1\rangle)/\sqrt 2 are the X-basis states. A single Z (phase-flip) error on any of the three physical qubits is detected by measuring the X-basis parities X_1 X_2 and X_2 X_3, which output a syndrome (s_1, s_2) that uniquely identifies the affected qubit. Recovery is a single Z on the flagged qubit. The code is Hadamard-conjugate to the bit-flip code: sandwiching the bit-flip encoding circuit with H^{\otimes 3} on either side produces the phase-flip code, because H X H = Z turns every bit-flip-detecting mechanism into a phase-flip-detecting one. The catch: the phase-flip code is blind to X errors the same way the bit-flip code is blind to Z errors. You need both — which is exactly what Shor's 9-qubit code delivers by stacking them.

The bit-flip code (the previous chapter) catches X errors. It is beautiful, compact, and — if you take it as the complete solution to quantum error correction — completely wrong.

Real quantum noise is not just bit-flip. A qubit sitting in a superconducting circuit, a trapped ion, or a photonic mode suffers at least two kinds of damage with roughly comparable probability: X errors that swap |0\rangle \leftrightarrow |1\rangle, and Z errors that flip the sign of |1\rangle without touching |0\rangle. The bit-flip code handles the first; it is defenceless against the second. A Z error on any qubit of the encoded state \alpha|000\rangle + \beta|111\rangle slips straight past the syndrome measurements and corrupts the logical state — because the syndromes Z_1 Z_2, Z_2 Z_3 commute with every Z and cannot see them.

Symmetry suggests the fix. If there is a code that catches X errors by encoding in the Z-basis (|000\rangle, |111\rangle) and measuring Z-basis parities, there ought to be a mirror-image code that catches Z errors by encoding in the X-basis and measuring X-basis parities. The Hadamard gate — which swaps X and Z, and swaps the \{|0\rangle, |1\rangle\} basis with the \{|+\rangle, |-\rangle\} basis — is the bridge between the two pictures. Conjugating the bit-flip code by H^{\otimes 3} produces a second code, the phase-flip code, that does exactly the mirror job.

That is this chapter. You will build the phase-flip code from scratch, see why it works, see the explicit Hadamard duality with the bit-flip code, and meet the limitation that motivates Shor's 9-qubit construction in the next chapter.

The X basis — a 30-second recap

The X basis consists of the two states

|+\rangle \;=\; \tfrac{1}{\sqrt 2}(|0\rangle + |1\rangle), \qquad |-\rangle \;=\; \tfrac{1}{\sqrt 2}(|0\rangle - |1\rangle).

They are the two eigenstates of the Pauli X operator, with eigenvalues +1 and -1 respectively:

X|+\rangle = +|+\rangle, \qquad X|-\rangle = -|-\rangle.

Why these are X eigenstates: X|0\rangle = |1\rangle and X|1\rangle = |0\rangle, so X(|0\rangle + |1\rangle) = |1\rangle + |0\rangle = (|0\rangle + |1\rangle) — the state is returned to itself, eigenvalue +1. For |-\rangle the minus sign flips, giving eigenvalue -1.

The Hadamard gate converts between the two bases: H|0\rangle = |+\rangle and H|1\rangle = |-\rangle, and conversely H|+\rangle = |0\rangle, H|-\rangle = |1\rangle. And the single most useful algebraic identity of this chapter is

H X H \;=\; Z, \qquad H Z H \;=\; X,

which says that conjugating X by H gives Z, and conjugating Z by H gives X. The Hadamard swaps the two Pauli operators.

Why HXH=Z: compute it in matrix form. H = \tfrac{1}{\sqrt 2}\begin{pmatrix}1 & 1\\1 & -1\end{pmatrix}, X = \begin{pmatrix}0 & 1\\1 & 0\end{pmatrix}. Then HX = \tfrac{1}{\sqrt 2}\begin{pmatrix}1 & 1\\-1 & 1\end{pmatrix}, and HXH = \tfrac{1}{2}\begin{pmatrix}1 & 1\\-1 & 1\end{pmatrix}\begin{pmatrix}1 & 1\\1 & -1\end{pmatrix} = \tfrac{1}{2}\begin{pmatrix}2 & 0\\0 & -2\end{pmatrix} = \begin{pmatrix}1 & 0\\0 & -1\end{pmatrix} = Z. The identity HZH=X follows from H^2 = I.

Keep HXH = Z in your head. It is the single equation driving this entire chapter.

The encoding

Start with a data qubit |\psi\rangle = \alpha|0\rangle + \beta|1\rangle and two ancillas in |0\rangle. The phase-flip code's encoding map is

|0\rangle \;\mapsto\; |0\rangle_L \;=\; |+\rangle|+\rangle|+\rangle \;=\; |{+}{+}{+}\rangle,
|1\rangle \;\mapsto\; |1\rangle_L \;=\; |-\rangle|-\rangle|-\rangle \;=\; |{-}{-}{-}\rangle,
\alpha|0\rangle + \beta|1\rangle \;\mapsto\; \alpha|{+}{+}{+}\rangle + \beta|{-}{-}{-}\rangle.

The encoded state lives in a two-dimensional subspace of the eight-dimensional three-qubit Hilbert space — the subspace spanned by |+++\rangle and |---\rangle, the code space of this code. Everything outside that subspace is "error territory".

The encoding circuit

Two equivalent circuits build |\psi\rangle_L from (\alpha|0\rangle + \beta|1\rangle)|0\rangle|0\rangle:

Route A — "bit-flip then Hadamard". Run the bit-flip encoding first (two CNOTs from qubit 1 to qubits 2 and 3), then apply H to all three qubits.

(\alpha|0\rangle + \beta|1\rangle)|00\rangle \;\xrightarrow{\text{CNOT}_{12}, \text{CNOT}_{13}}\; \alpha|000\rangle + \beta|111\rangle \;\xrightarrow{H^{\otimes 3}}\; \alpha|{+}{+}{+}\rangle + \beta|{-}{-}{-}\rangle.

Why the final step works: H^{\otimes 3}|000\rangle = (H|0\rangle)^{\otimes 3} = |+\rangle^{\otimes 3} = |{+}{+}{+}\rangle, and similarly H^{\otimes 3}|111\rangle = |{-}{-}{-}\rangle. The three Hadamards applied in parallel factor through the tensor product.

Route B — "Hadamard then CNOT then Hadamard". Apply H to qubit 1, then two CNOTs with qubit 1 as control, then three final Hadamards. This gives the same output — it is just Route A with an extra H^2 = I pair inserted at the start for free. Route A is cleaner; we use it from here on.

Either way, the encoded state is |\psi\rangle_L = \alpha|{+}{+}{+}\rangle + \beta|{-}{-}{-}\rangle.

Phase-flip code encoding circuitA three-wire quantum circuit. The top wire starts at alpha |0⟩ + beta |1⟩, the middle and bottom at |0⟩. Two CNOTs run with qubit 1 as control and qubits 2, 3 as targets, followed by a box labelled H on each wire. The output is labelled alpha |+++⟩ + beta |---⟩.Phase-flip code: encoding circuit (Route A)α|0⟩+β|1⟩|0⟩|0⟩CNOT₁₂CNOT₁₃HHHapply H to all threeα|+⟩|+⟩ + β|−⟩...
The phase-flip encoding circuit. First run the bit-flip encoding — two CNOTs from qubit 1 to qubits 2 and 3, which produces $\alpha|000\rangle + \beta|111\rangle$. Then apply a Hadamard to each qubit, rotating each $|0\rangle$ to $|+\rangle$ and each $|1\rangle$ to $|-\rangle$. The output $\alpha|{+}{+}{+}\rangle + \beta|{-}{-}{-}\rangle$ is the logical encoded state.

Why Z errors are detectable — intuition first

A Z error on a single qubit does this:

Z|+\rangle \;=\; |-\rangle, \qquad Z|-\rangle \;=\; |+\rangle.

Why Z flips |+\rangle and |-\rangle: Z|0\rangle = |0\rangle and Z|1\rangle = -|1\rangle, so Z(|0\rangle + |1\rangle) = |0\rangle - |1\rangle — the plus sign becomes minus. That is |+\rangle \to |-\rangle. By the same arithmetic |-\rangle \to |+\rangle.

So a Z error in the X basis is exactly what an X error is in the Z basis — it flips the basis element. The encoding \alpha|{+}{+}{+}\rangle + \beta|{-}{-}{-}\rangle suffers a Z error on qubit 2 (say), producing

\alpha|{+}{-}{+}\rangle + \beta|{-}{+}{-}\rangle.

One of the three +/- labels in each basis ket has flipped. In the X basis, that is exactly a bit-flip on qubit 2.

The picture is now the bit-flip picture, just with +/- instead of 0/1: three qubits, each of which "agrees" (all plus or all minus) in the encoded state, and a single-qubit error making one of them disagree. The detection mechanism must therefore be "measure whether adjacent qubits agree in the X basis". That is the syndrome.

Syndrome measurement — the X-basis parities

The two stabiliser observables of the phase-flip code are

S_1 \;=\; X_1 X_2, \qquad S_2 \;=\; X_2 X_3.

Each of these is a tensor product of Pauli X's, acting on the specified pair of qubits and identity on the third. Their eigenstates in the X basis are exactly analogous to how Z_i Z_j has eigenstates in the Z basis:

  • |{+}{+}\rangle is a +1 eigenstate of X_1 X_2 (both plus, parity +1).
  • |{-}{-}\rangle is a +1 eigenstate (both minus, (-1)(-1) = +1).
  • |{+}{-}\rangle and |{-}{+}\rangle are -1 eigenstates (one of each, parity -1).

Apply this to the code space. Every state in the code space is a linear combination of |{+}{+}{+}\rangle and |{-}{-}{-}\rangle. Both of these are +1 eigenstates of S_1 (first two qubits agree in the X basis) and +1 eigenstates of S_2 (last two qubits agree). So every code-space state satisfies

S_1 |\psi\rangle_L = +|\psi\rangle_L, \qquad S_2 |\psi\rangle_L = +|\psi\rangle_L.

Measuring S_1 and S_2 on an uncorrupted encoded state returns (+1, +1) with certainty, and the measurement does not disturb the state.

Now a Z error takes the state out of the code space and changes the eigenvalues:

Error State after error S_1 = X_1 X_2 S_2 = X_2 X_3
I \alpha|{+}{+}{+}\rangle + \beta|{-}{-}{-}\rangle +1 +1
Z_1 \alpha|{-}{+}{+}\rangle + \beta|{+}{-}{-}\rangle -1 +1
Z_2 \alpha|{+}{-}{+}\rangle + \beta|{-}{+}{-}\rangle -1 -1
Z_3 \alpha|{+}{+}{-}\rangle + \beta|{-}{-}{+}\rangle +1 -1

Four distinct syndromes, four distinguishable error locations. The syndrome (s_1, s_2) uniquely pinpoints which qubit suffered the phase flip. Apply Z to that qubit and — because Z^2 = I — the error is exactly undone, and the state returns to the code space with amplitudes \alpha, \beta untouched.

Phase-flip code syndrome measurement in the X basisA three-wire circuit with two ancilla wires at the top, each initialised to |0⟩. The ancillas are Hadamarded, then used as controls for controlled-X-X gates onto qubit pairs (1,2) and (2,3). The ancillas are Hadamarded again and measured, yielding syndrome bits s₁ and s₂.Syndrome extraction: measures X₁X₂ and X₂X₃|0⟩ₐ|0⟩ₐq₁q₂q₃HHXXancilla 1 → X₁X₂XXancilla 2 → X₂X₃HHMM= s₁= s₂
Phase-flip syndrome circuit. Two ancillas are Hadamarded to put them into $|+\rangle$, then each one controls an $X$ on the appropriate pair of data qubits — this implements the controlled-$X_i X_j$ operation on the data. A final Hadamard on the ancillas converts the stabiliser eigenvalue into a measurable $\{0, 1\}$ outcome. Measuring the ancillas gives the two syndrome bits $s_1, s_2$. The data qubits are not measured.

The Hadamard duality — one code from the other

The phase-flip code is not a new invention. It is the bit-flip code with Hadamards stapled on.

Let E_{\text{bit}} be the bit-flip encoding unitary (|\psi\rangle|00\rangle \mapsto \alpha|000\rangle + \beta|111\rangle for the three-qubit case, zero-padded with ancillas), and let E_{\text{phase}} be the phase-flip encoding unitary. Then

E_{\text{phase}} \;=\; H^{\otimes 3} \cdot E_{\text{bit}}.

Similarly, if S^{\text{bit}}_1 = Z_1 Z_2 and S^{\text{bit}}_2 = Z_2 Z_3 are the bit-flip stabilisers, and S^{\text{phase}}_1 = X_1 X_2 and S^{\text{phase}}_2 = X_2 X_3 are the phase-flip ones, then by H Z H = X:

H^{\otimes 3} \cdot S^{\text{bit}}_i \cdot H^{\otimes 3} \;=\; S^{\text{phase}}_i \qquad (i = 1, 2).

And bit-flip errors X_i become phase-flip errors Z_i under the same conjugation:

H^{\otimes 3} \cdot X_i \cdot H^{\otimes 3} \;=\; Z_i.

Every operational piece of the bit-flip code has a phase-flip counterpart obtained by sandwiching with H^{\otimes 3}. Encoding, stabilisers, detectable errors, recovery — all mirror through the Hadamard layer.

Hadamard duality between bit-flip and phase-flip codesTwo boxes side by side. Left box labelled bit-flip code summarises: encodes in |000⟩ |111⟩, detects X errors, stabilisers Z₁Z₂ Z₂Z₃, recovery X. Right box labelled phase-flip code summarises: encodes in |+++⟩ |---⟩, detects Z errors, stabilisers X₁X₂ X₂X₃, recovery Z. Between them is a double arrow labelled H⊗3 conjugation, with the identity HZH = X annotated below.Bit-flip codeencoding: α|000⟩ + β|111⟩basis: Z (computational)stabilisers: Z₁Z₂, Z₂Z₃detects: X errorsrecovery: X on flagged qubitblind to Z errorsH⊗³HZH = XHXH = ZPhase-flip codeencoding: α|+++⟩ + β|−−−⟩basis: X (Hadamard)stabilisers: X₁X₂, X₂X₃detects: Z errorsrecovery: Z on flagged qubitblind to X errorsConjugating every operator by H⊗3 turns one code into the other
The two sibling codes. Every operational piece of the bit-flip code — encoding, stabilisers, error set, recovery — has a phase-flip counterpart obtained by sandwiching with a layer of Hadamards. The two codes are algebraically the same object, viewed in two different bases.

This duality is not a trick of notation — it is a general principle. Under H^{\otimes n} conjugation, any code protecting against X-type errors becomes a code protecting against Z-type errors. When we meet CSS codes (ch.120) and stabiliser codes in full generality, this duality will reappear as part of the classification of quantum codes into X-type and Z-type stabilisers.

Worked examples

Example 1: detect and correct a Z error on |+⟩_L

Show end-to-end how the phase-flip code catches a Z error on one physical qubit of the encoded state |+\rangle_L.

Setup. The logical input is |+\rangle = \tfrac{1}{\sqrt 2}(|0\rangle + |1\rangle). Encode it:

|+\rangle_L \;=\; \tfrac{1}{\sqrt 2}(|{+}{+}{+}\rangle + |{-}{-}{-}\rangle).

Why: the encoding map sends |0\rangle \to |{+}{+}{+}\rangle and |1\rangle \to |{-}{-}{-}\rangle, and it is linear, so it sends \tfrac{1}{\sqrt 2}(|0\rangle + |1\rangle) to \tfrac{1}{\sqrt 2}(|{+}{+}{+}\rangle + |{-}{-}{-}\rangle). Linearity of the encoding is essential: it is a unitary map, and unitaries are linear.

Step 1. The error happens. A phase-flip hits qubit 1. Apply Z_1 = Z \otimes I \otimes I:

Z_1 |+\rangle_L \;=\; \tfrac{1}{\sqrt 2}(Z_1|{+}{+}{+}\rangle + Z_1|{-}{-}{-}\rangle) \;=\; \tfrac{1}{\sqrt 2}(|{-}{+}{+}\rangle + |{+}{-}{-}\rangle).

Why Z_1|{+}{+}{+}\rangle = |{-}{+}{+}\rangle: Z_1 acts as Z on qubit 1 and identity on qubits 2, 3. Z|+\rangle = |-\rangle, so qubit 1 flips + \to -; qubits 2, 3 unchanged.

The state is no longer in the code space.

Step 2. Measure S_1 = X_1 X_2. Evaluate on each basis ket:

  • X_1 X_2 |{-}{+}{+}\rangle: X_1|{-}\rangle = -|{-}\rangle, X_2|{+}\rangle = +|{+}\rangle, |{+}\rangle on qubit 3 untouched. Total: (-1)(+1) = -1 times |{-}{+}{+}\rangle.
  • X_1 X_2 |{+}{-}{-}\rangle: (+1)(-1) = -1 times |{+}{-}{-}\rangle.

Both terms give eigenvalue -1, so the state is a -1 eigenstate of S_1. The measurement returns s_1 = -1 deterministically, with no disturbance to the amplitudes.

Step 3. Measure S_2 = X_2 X_3.

  • X_2 X_3 |{-}{+}{+}\rangle: (+1)(+1) = +1.
  • X_2 X_3 |{+}{-}{-}\rangle: (-1)(-1) = +1.

s_2 = +1.

Step 4. Read the syndrome. (s_1, s_2) = (-1, +1) matches the Z_1 row of the syndrome table. The error is on qubit 1.

Step 5. Apply the correction Z_1. Since Z^2 = I:

Z_1 \cdot Z_1 |+\rangle_L \;=\; |+\rangle_L.

Back to the code space, amplitudes preserved.

Result. |+\rangle_L is recovered exactly. The logical information — the equal superposition of |0\rangle_L and |1\rangle_L — survives a single-qubit Z error. Had two phase flips occurred in the same correction cycle, the syndrome would mis-identify them as a different single-qubit error and the recovery would actually introduce a logical flip, but at probability O(p^2) rather than O(p).

One phase-flip correction cycle on |+⟩_LA four-stage flow. Stage 1 encoded state (|+++⟩ + |---⟩)/√2. Stage 2 after Z₁ error (|-++⟩ + |+--⟩)/√2. Stage 3 syndrome reads (-1, +1) flagging qubit 1. Stage 4 after Z₁ recovery back to (|+++⟩ + |---⟩)/√2.encoded |+⟩_L(|+++⟩ + |---⟩)/ √2S₁=+1, S₂=+1Z₁after error(|-++⟩ + |+--⟩)/ √2S₁=-1, S₂=+1readsyndrome(s₁, s₂) = (−1, +1)→ Z on qubit 1apply Z₁Z₁corrected(|+++⟩+|---⟩)/ √2in code spaceα, β never measured — only the X-basis parity is readthe logical superposition is preserved throughout
A $Z$ error on qubit 1 knocks the state out of the code space. Measuring $X_1 X_2$ and $X_2 X_3$ returns $(-1, +1)$, which uniquely identifies the affected qubit. Applying $Z_1$ restores the encoded state exactly. The logical amplitudes $\alpha = \beta = 1/\sqrt 2$ of $|+\rangle$ are untouched by any step.

What this shows. The phase-flip code works by relabelling the bit-flip protocol. Everything the bit-flip code did in the \{|0\rangle, |1\rangle\} basis — encoding by tripling, syndrome by Z-parity, correction by X — has a dual here in the \{|+\rangle, |-\rangle\} basis with X and Z swapped.

Example 2: the phase-flip code is blind to X errors

The phase-flip code's mirror-image weakness: it does nothing to protect against X errors. Show this explicitly by applying an X error and watching the syndrome fail to detect it.

Setup. Take an encoded state |\psi\rangle_L = \alpha|{+}{+}{+}\rangle + \beta|{-}{-}{-}\rangle (arbitrary \alpha, \beta).

Step 1. What X does in the X basis. X|+\rangle = +|+\rangle and X|-\rangle = -|-\rangle — so X on a single X-basis state does not change it as a vector, but the second case contributes a sign. Why: |+\rangle and |-\rangle are eigenstates of X with eigenvalues +1 and -1. An X operator applied to its own eigenstate returns the eigenstate times the eigenvalue — so |+\rangle is returned unchanged and |-\rangle picks up a -1.

Step 2. Apply X_1.

X_1 |\psi\rangle_L \;=\; \alpha \, (X|+\rangle)|{+}{+}\rangle + \beta \, (X|-\rangle)|{-}{-}\rangle \;=\; \alpha|{+}{+}{+}\rangle - \beta|{-}{-}{-}\rangle.

The relative phase between the two logical basis kets has flipped: \beta \to -\beta. In the logical qubit's view, \alpha|0\rangle_L + \beta|1\rangle_L \to \alpha|0\rangle_L - \beta|1\rangle_L — this is a logical Z, not nothing.

Step 3. Measure the syndrome. Evaluate S_1 = X_1 X_2 on each term:

  • X_1 X_2 |{+}{+}{+}\rangle = (+1)(+1)|{+}{+}{+}\rangle = +|{+}{+}{+}\rangle.
  • X_1 X_2 |{-}{-}{-}\rangle = (-1)(-1)|{-}{-}{-}\rangle = +|{-}{-}{-}\rangle.

So the corrupted state is still a +1 eigenstate of S_1. Similarly a +1 eigenstate of S_2. The syndrome reads (+1, +1) — the same as "no error".

Step 4. Recovery attempt. The syndrome says "do nothing". You do nothing. The logical-Z error remains. The logical qubit is now in the state \alpha|0\rangle_L - \beta|1\rangle_L instead of \alpha|0\rangle_L + \beta|1\rangle_L — a different logical state, corrupted in a way the code cannot detect.

Result. A single X error on any physical qubit of the phase-flip code is invisible to the syndrome and produces a logical Z on the encoded qubit. The phase-flip code protects against Z errors at the cost of being completely exposed to X errors. In a real noise model where both X and Z happen with comparable probability, the phase-flip code alone does worse than the bare qubit, because every X error that would have been a visible bit-flip becomes a silent logical phase-flip.

X errors are invisible to the phase-flip codeA simple flow diagram. Box 1: encoded state α|+++⟩ + β|---⟩. An X₁ error arrow leads to box 2: α|+++⟩ − β|---⟩ with a note that the relative phase has flipped. Box 3 shows the syndrome reading (+1, +1) — indistinguishable from no error. Below, a caption: the code failed silently.encoded |ψ⟩_Lα|+++⟩ + β|---⟩logical ψ = α|0⟩+β|1⟩X₁after X on qubit 1α|+++⟩ − β|---⟩logical ψ = α|0⟩−β|1⟩a logical Z errorreadsyndrome reads(s₁, s₂) = (+1, +1)"no error" — identical tothe uncorrupted caseX error → silent logical Z → code fails without warningphase-flip code alone is incomplete; you need the bit-flip code too
An $X$ error on any single qubit of the phase-flip code is indistinguishable from no error at the syndrome level — but it has already flipped the relative phase of the encoded logical qubit, producing a logical $Z$. The phase-flip code is perfect against $Z$ errors and defenceless against $X$ errors. The next chapter (Shor's 9-qubit code) fixes this by layering the two codes.

What this shows. No three-qubit code can protect against both X and Z errors simultaneously — the information-theoretic capacity is not there. The bit-flip code picks X, the phase-flip code picks Z, and each fails against the other. Shor's 9-qubit code concatenates them (3 blocks of 3) to get both.

Why this matters. The phase-flip code is not a production-grade protection scheme. Its real job is pedagogical and conceptual: it establishes the Hadamard duality between X-type and Z-type codes, which is the skeleton of the CSS code construction (Calderbank-Shor-Steane, 1996). Every CSS code is built from two classical binary codes, one detecting X-type errors and one detecting Z-type errors, glued together by the same Hadamard-basis trick you just saw. The phase-flip code is the simplest non-trivial CSS code, and understanding it is the entry point to understanding every CSS-family code (Steane's 7-qubit code, surface codes, colour codes).

Common confusions

  • "The phase-flip code is a different code from the bit-flip code." Algebraically, no. The two codes are unitarily equivalent by the H^{\otimes 3} transformation: every operational element of one is obtained by sandwiching the corresponding element of the other with Hadamards. They are the same code in two different bases. Pragmatically, yes — they detect different error types, because "error type" is not basis-invariant in the way the code structure is.

  • "X errors do nothing, so the phase-flip code ignores them safely." Wrong. X|+\rangle = |+\rangle is true, but X|-\rangle = -|-\rangle. The relative sign on |-\rangle propagates into the encoded state as a logical Z — a real, observable error that corrupts the logical qubit. The code does not detect the error and the error is not harmless. That is the worst combination.

  • "Syndrome measurement needs Hadamards before and after." The stabiliser X_1 X_2 is measured with a standard ancilla-based circuit: Hadamard the ancilla, apply controlled-X on qubits 1 and 2 from the ancilla, Hadamard the ancilla again, measure. That looks like "Hadamards sandwiching the operation", because converting an X-basis measurement to a Z-basis measurement requires a Hadamard on each end. You are not Hadamarding the data qubits; you are Hadamarding the ancilla so the measurement reads out the X-parity as a standard computational-basis bit.

  • "The code works as long as errors are small." No — the code works against any single-qubit Z error, of any strength, regardless of whether it is a small rotation e^{-i\epsilon Z} or a full Z. Discretisation (see why QEC is hard) guarantees that a small rotation gets projected by the syndrome measurement onto either "no error" (with high probability) or "full Z on one qubit" (with small probability). Either outcome is then corrected exactly by the code. This is one of the most counterintuitive features of QEC: the protection is against an error channel, not against a specific error magnitude.

  • "Phase-flip is less important than bit-flip." False. In most physical noise models — superconducting qubits, trapped ions, photonic modes — T_2 (the phase-coherence time) is the limiting factor, not T_1 (the energy-relaxation time that causes bit-flips). Phase errors dominate. A real quantum device without phase-flip protection is like a leaky boat with a bucket labelled "bails out splashes" but no way to handle the slow seep through the hull.

Going deeper

If you came here to see the phase-flip code in action and understand how it dualises with the bit-flip code, you have it. This section sketches the formal CSS construction and the stabiliser-formalism picture for readers preparing for the rest of Part 14.

Both codes as [3, 1] CSS codes

A CSS code (Calderbank-Shor-Steane, 1996) is built from two classical linear binary codes C_1, C_2 \subseteq \mathbb{F}_2^n with C_2 \subseteq C_1. The quantum code's logical basis states are

|x + C_2\rangle \;=\; \frac{1}{\sqrt{|C_2|}} \sum_{y \in C_2} |x + y\rangle, \qquad x \in C_1 / C_2,

i.e., equal superpositions over cosets of C_2 in C_1. The bit-flip code corresponds to C_1 = \{000, 111\} (the classical 3-bit repetition code) and C_2 = \{000\}: the logical bases are |000\rangle and |111\rangle directly. The phase-flip code is the dual CSS construction with the roles of C_1 and C_2 swapped (in the sense that the Hadamard-conjugated state is the coset superposition of the dual codes).

More concretely: the phase-flip encoding \alpha|{+}{+}{+}\rangle + \beta|{-}{-}{-}\rangle, when expanded in the computational basis, equals

|{+}{+}{+}\rangle \;=\; \tfrac{1}{2\sqrt 2}\sum_{x \in \{0,1\}^3} |x\rangle, \qquad |{-}{-}{-}\rangle \;=\; \tfrac{1}{2\sqrt 2}\sum_{x \in \{0,1\}^3} (-1)^{|x|} |x\rangle,

where |x| is the Hamming weight of x. So

|0\rangle_L = \tfrac{1}{2\sqrt 2}(|000\rangle + |001\rangle + |010\rangle + |011\rangle + |100\rangle + |101\rangle + |110\rangle + |111\rangle),
|1\rangle_L = \tfrac{1}{2\sqrt 2}(|000\rangle - |001\rangle - |010\rangle + |011\rangle - |100\rangle + |101\rangle + |110\rangle - |111\rangle).

These are the two even-weight and odd-weight coset superpositions of the parity code \{x : |x| \text{ even}\}, exactly the CSS construction for this code pair.

Stabiliser generators

In the stabiliser formalism (ch.119), a code is defined by a set of commuting Pauli operators that fix every code-space state. For the phase-flip code, the generators are

S_1 = X \otimes X \otimes I, \qquad S_2 = I \otimes X \otimes X.

Every state in the code space satisfies S_i |\psi\rangle_L = +|\psi\rangle_L for i = 1, 2. The logical operators are

Z_L = Z \otimes Z \otimes Z, \qquad X_L = X \otimes I \otimes I

(or any weight-odd product of X's, since any odd-weight X is equivalent modulo the stabiliser). Z_L distinguishes |0\rangle_L from |1\rangle_L (eigenvalues +1 and -1) and X_L flips between them.

Contrast with the bit-flip code:

S^{\text{bit}}_1 = Z \otimes Z \otimes I, \quad S^{\text{bit}}_2 = I \otimes Z \otimes Z, \quad Z^{\text{bit}}_L = Z \otimes I \otimes I, \quad X^{\text{bit}}_L = X \otimes X \otimes X.

The generators and the logical operators are swapped under X \leftrightarrow Z — the Hadamard duality in stabiliser language.

Toward Shor's 9-qubit code

The phase-flip code protects against Z errors and is blind to X. The bit-flip code is the opposite. Neither alone is useful for real noise, which contains both in roughly equal measure. Shor's 9-qubit code (ch.118) fixes this by concatenation: each of the three qubits in the outer phase-flip code is itself encoded into three physical qubits by the bit-flip code. The resulting 9-qubit state inherits the Z-error protection of the outer code and the X-error protection of the inner code — and, because Y = iXZ, it also corrects Y errors, and by the discretisation theorem it corrects any single-qubit error. Concatenation of the bit-flip and phase-flip codes is the simplest way to build a fully error-correcting quantum code, and Shor did it in the first QEC paper ever published. The next chapter walks through the construction.

Where this leads next

  • Bit-flip code — the partner code. Reads this chapter's contents in the computational basis.
  • Shor 9-qubit code — combines bit-flip and phase-flip codes. Corrects every single-qubit error.
  • Why QEC is hard — no-cloning, continuous errors, measurement collapse, and the three insights that circumvent them.
  • CSS codes — the general construction that bit-flip and phase-flip codes are the simplest instance of.
  • Stabilizer formalism intro — the unifying language for every code in this part.

References

  1. Peter Shor, Scheme for reducing decoherence in quantum computer memory (1995), Phys. Rev. A 52, R2493 — arXiv:quant-ph/9508027. The original 9-qubit code paper; introduces the phase-flip code as an intermediate step.
  2. Andrew Steane, Multiple particle interference and quantum error correction (1996) — arXiv:quant-ph/9601029. The companion early QEC paper; introduces the 7-qubit code.
  3. John Preskill, Lecture Notes on Quantum Computation, Chapter 7 — theory.caltech.edu/~preskill/ph229. The pedagogical presentation of bit-flip, phase-flip, and Shor codes, with the Hadamard duality explicit.
  4. Nielsen and Chuang, Quantum Computation and Quantum Information (2010), §10.1 (three-qubit codes) — Cambridge University Press.
  5. Daniel Gottesman, Stabilizer codes and quantum error correction (PhD thesis, 1997) — arXiv:quant-ph/9705052. The stabiliser-formalism treatment.
  6. Wikipedia, Quantum error correction — overview with all three-qubit codes side by side.