Idea. Quantum information is fragile, so it is stored redundantly. The simplest code spreads one logical bit over d physical qubits (|0> -> |00..0>, |1> -> |11..1>). Neighbouring ancilla qubits measure the parities q_i xor q_(i+1); they reveal where a bit flip happened without revealing the stored value. A majority vote then repairs the flips.
Model. Each data qubit independently suffers a bit flip with probability p in one round. The decoder is perfect and the syndrome measurement is perfect (the "code-capacity" model). The logical qubit fails when more than d/2 qubits flipped, so
p_L = sum over k > d/2 of C(d,k) p^k (1-p)^(d-k); for d = 3 this is 3p^2 - 2p^3, about 3p^2 for small p.
Independent checks. (1) A brute-force enumeration of all 2^d error patterns with a majority decoder is compared with the binomial formula. (2) The d = 3 closed form. (3) Monte Carlo counts are compared with the exact value as a z-score. The depolarizing exact value comes from a separate dynamic-programming sum over (number of X-parts, parity of Z-parts).
Simplifications and honesty. Real devices have faulty measurements and gates, correlated errors and leakage; their thresholds are far lower than the break-even p = 1/2 shown here (published surface-code thresholds are around 1 percent per operation for circuit-level noise; treat that as a typical literature value to verify). Nothing here shows a real quantum advantage, and "perfect" error correction does not exist: p_L is reduced, never zero.
Chip, qubit and coupler models were made in Blender; the logic runs in Three.js r160.