Curriculum / Noise & Error Correction / Shor's 9-Qubit Code

Lesson 7 of 14ReadingPro+100 XP

Shor's 9-Qubit Code

The first code to correct arbitrary single-qubit errors.

Shor's 9-Qubit Code

Shor's 9-qubit code, introduced in 1995, was the first quantum error correcting code to protect against BOTH bit flip (X) and phase flip (Z) errors. It encodes 1 logical qubit in 9 physical qubits and can correct any single-qubit error.

The structure:

Shor's code is a concatenation of two simpler codes:

  1. 1.The 3-qubit phase flip code (outer): encodes logical |0⟩ as (|+⟩|+⟩|+⟩) and |1⟩ as (|−⟩|−⟩|−⟩)
  2. 2.The 3-qubit bit flip code (inner): each of the 3 |+⟩/|−⟩ blocks is further encoded as |000⟩/|111⟩ or |+++⟩/|−−−⟩

The codewords are:

|0̄⟩ = (|000⟩+|111⟩)(|000⟩+|111⟩)(|000⟩+|111⟩) / 2√2 |1̄⟩ = (|000⟩−|111⟩)(|000⟩−|111⟩)(|000⟩−|111⟩) / 2√2

Encoding circuit:

The encoder has three layers, in this order:

Step 1, outer fan-out:          cx(0,3), cx(0,6)
   (copies |ψ⟩'s amplitudes onto the block leaders q0, q3, q6)

Step 2, leader basis change:    h(0), h(3), h(6)
   (each block leader becomes a |+⟩/|−⟩ phase qubit)

Step 3, inner bit flip fan-out: cx(0,1), cx(0,2)
                                cx(3,4), cx(3,5)
                                cx(6,7), cx(6,8)

The Hadamards go on the block leaders BEFORE the within-block fan-out, and there is no Hadamard layer at the end. Each block then holds (|000⟩±|111⟩)/√2, the bit flip encoding of the leader's phase state.

Concatenation: combining codes for universal protection

The Shor code protects against X errors using the inner bit flip code (within each 3-qubit block) and against Z errors using the outer phase flip code (across the three blocks). A Z error on any physical qubit corrupts one block's phase: the outer phase flip code detects and corrects it. An X error within a block is caught by the inner bit flip code. This 'inner-outer' concatenation structure is general and underlies many practical quantum codes.

Error correction procedure:

For bit flip errors (X):

  • Within each 3-qubit block, measure the parity of adjacent pairs
  • The syndrome identifies which physical qubit (0..8) has an X error
  • Apply X to correct

For phase flip errors (Z):

  • Measure X-basis parities across blocks (requires Hadamard basis change)
  • The syndrome identifies which block has a Z error
  • Apply Z to any qubit in that block to correct

The Shor code has distance 3: it can detect up to 2 errors or correct 1 error.

This is the opening of the lesson. The full walkthrough, the interactive circuit, and the graded challenge continue inside myqubit.

How this lesson works

A guided reading lesson with interactive knowledge checks. Concepts are explained step by step with circuit diagrams and runnable examples, and you confirm understanding before moving on.

Part of: Noise & Error Correction

Understand quantum noise and build error correction codes to protect quantum information.

This lesson is part of Pro

Unlock Noise & Error Correction and all 10 tracks with Pro: $12.99/month, $79/year, or $97 lifetime. Start with the free track first if you are new.