# Code Distance and Threshold Theorem
Two ideas govern whether [[Quantum Error Correction]] actually helps: the **code distance** (how much protection a given code provides) and the **threshold theorem** (the condition under which adding protection wins).
## Code distance
The **distance** $d$ of a code is the smallest number of physical errors needed to corrupt the [[Physical vs Logical Qubits|logical]] information undetected. A code of distance $d$ can correct up to $\lfloor (d-1)/2 \rfloor$ errors. Bigger distance = more resilience, bought with more physical [[Qubit|qubits]]. In the [[Surface Code]], distance is roughly the width of the qubit patch.
## The threshold theorem
There exists a critical physical error rate $p_\text{th}$ — the **fault-tolerance threshold** — with a sharp dichotomy:
- If the physical error rate $p < p_\text{th}$: increasing the distance drives the logical error rate **down**, exponentially.
- If $p > p_\text{th}$: adding qubits makes things **worse** — the correction machinery introduces more errors than it removes.
$
p < p_\text{th} \;\Rightarrow\; P_\text{logical} \sim \Big(\frac{p}{p_\text{th}}\Big)^{\,d/2} \xrightarrow{\;d\to\infty\;} 0
$
> [!intuition] The leaky-bucket tipping point
> If you bail water faster than it leaks in, a bigger bucket eventually stays dry. If you bail slower, a bigger bucket just holds more water before it overflows. The threshold is the break-even bailing rate.
## "Below threshold" as a milestone
Demonstrating **below threshold** means showing experimentally that *larger code distance yields fewer logical errors* — proof that the platform's [[Gate Fidelity|gates]] are good enough for error correction to pay off. It is the gateway to scalable, fault-tolerant computing.
## Related
- [[Quantum Error Correction]]
- [[Surface Code]]
- [[Gate Fidelity]]
- [[Physical vs Logical Qubits]]
- [[Syndrome Extraction]]