the ground / stratum · Pattern
Every channel corrupts. A scratched disc, a faint radio, a cosmic ray flipping one bit in a chip on Mars — the message arrives a little wrong. The astonishing fix is to send it so deliberately spread out in the space of all possible messages that even after a few bits flip, it still lands nearer its true self than to any other. The geometry of that spreading is sphere-packing; the codes that pack it with no waste at all are called perfect — and there are only a handful in the entire universe of codes.
Think of every 7-bit string as a point in a cube of 2⁷ = 128 corners. Flipping one bit is a single step to a neighbouring corner. If you scatter a set of codewords — the only strings you ever actually send — so that any two are at least three steps apart, then a single flip can never carry one codeword onto another, or even halfway. The corrupted string still has a unique nearest codeword, and the receiver just snaps back to it. That is error correction: not detecting that something broke, but knowing exactly what it should have been.
The classic example is Richard Hamming's code of 1950. Hamming was at Bell Labs running computations on a relay machine that ran unattended over weekends; when it hit a parity error it would simply halt and discard the job, and he would arrive on Monday to nothing. “Damn it, if the machine can detect an error,” he recalled thinking, “why can't it locate the position of the error and correct it?” So he built a code that does. It takes 4 data bits, adds 3 parity bits, and the seven of them together can survive any single flip — and tell you which bit it was. The trick is three overlapping parity checks. Watch one heal.
Set the 4 data bits; the 3 parity bits are computed so each of the three circles holds an even number of 1s. Now click any bit in the diagram to flip it — a transmission error. The circles that contain it turn odd; the one bit sitting in exactly those circles and no others is the culprit. That intersection is the syndrome.
transmitted codeword (7 bits)
syndrome = A·1 + B·2 + C·4 = 0 → no error
The receiver never saw your original — it only sees the 7 arriving bits and the three parities. With at most one flip, that is always enough. Try two flips and watch it confidently heal the wrong bit: the honest price of a code that only guarantees one.
What you are watching is a tiny computer that reads three parity bits as a 3-digit binary number — and that number is exactly the position of the broken bit, 1 through 7, or 000 for “all clear.” That is not a lucky arrangement; the code is built so the three parity checks spell the address of any single error in binary. (The offline proof in research/perfect-codes/hamming.mjs flips every one of the 7 × 16 = 112 possible single-bit errors and confirms all 112 are healed.)
But the deep fact is geometric, and it is the reason this particular code is famous. Draw all 128 seven-bit strings as points. Around each of the 16 codewords, draw the ball of everything within one flip of it — that's the codeword plus its 7 neighbours, 8 points. Sixteen codewords, eight points each: 16 × 8 = 128. Exactly the whole cube. No string is left over, and no string is claimed by two codewords. The balls don't just avoid overlapping — they tile the entire space.
A code is perfect when its correction-balls fill the space with no gap and no overlap. Every possible received string has exactly one home.
That tiling has a name: the code is perfect. It wrings the sphere-packing bound — the hard ceiling that says you cannot have more codewords than the space has room for — at dead equality. In symbols, a code over an alphabet of q letters, length n, with M codewords correcting t errors, is perfect exactly when
— codewords times ball-volume equals the whole space. Dial the instrument below through the codes that achieve it, and watch the two sides of that equation lock.
For Hamming(7,4), all 128 seven-bit strings, each tile coloured by which of the 16 codewords owns it (is within one flip). Sixteen baskets of eight, tiling the cube — no gap, no overlap.
Now choose a perfect code and watch its sphere-packing identity balance — codewords × ball-volume = whole space:
The Hamming family runs forever — one perfect single-error-correcting code for every redundancy r, of length (qʳ−1)/(q−1). But two codes stand apart, correcting more than one error and still perfect. The binary Golay code [23, 12, 7] corrects any 3 errors in 23 bits; its 2¹²·2048 = 2²³ packing is exact, and its big brother the extended [24,12,8] code is so symmetric that its symmetry group is the sporadic simple group M₂₄. From that extended code one can build the Leech lattice in 24 dimensions — which gives the densest sphere packing there, proven optimal only in 2017 (Cohn, Kumar, Miller, Radchenko & Viazovska; the optimality proof itself uses modular forms, not the code). The ternary Golay code [11, 6, 5] does the same trick over a three-letter alphabet, correcting 2 errors with 3⁶·243 = 3¹¹. Both are built and checked from scratch in research/perfect-codes/golay.mjs and census.mjs.
And then it stops. In 1973 Aimo Tietäväinen, completing a line of work by van Lint, proved that this short list is the whole story: over any finite field, the only perfect codes are the trivial ones, the Hamming-parameter codes, and those two Golay codes. Not “the only ones we've found” — the only ones that can exist, anywhere, forever. Perfection is almost never available; where it is, mathematics has already enumerated it.
Here is the twist that makes the theorem worth proving. The sphere-packing equation is a necessary condition: any perfect code must satisfy it. You might hope it's also sufficient — that if the arithmetic balances, a code is waiting to be found. It is not. The cleanest witness is a hypothetical binary code of length 90 correcting 2 errors. Its ball would hold 1 + 90 + C(90,2) = 4096 = 2¹² strings, and 2⁷⁸ · 2¹² = 2⁹⁰ — the identity closes perfectly. It even passes Lloyd's theorem, the deeper necessary test that trips up most impostors. Every standard checkpoint says yes. Yet no such code exists; its impossibility falls straight out of the classification (it is neither Hamming nor Golay). Test it yourself, and test your own parameters, below.
The entire roster of perfect codes over a finite field (van Lint 1971 · Tietäväinen 1973). Three trivial kinds, one infinite family, two exceptional Golay codes. That is all of them, for every alphabet, for all time.
Ask whether a perfect code can exist. Enter parameters; the machine checks the sphere-packing bound (necessary) and the classification (sufficient), and tells you which gate fails.
The checker is faithful to both gates. Type the phantom — q=2, n=90, t=2, k=78 — and the sphere-packing line glows green while the verdict stays red: the count permits it, the classification forbids it. Type q=2, n=23, t=3, k=12 and you've found Golay. Most parameter sets fail the count outright; of the few that pass, almost all are phantoms. The rarity is the whole point.
Recomputed live, and checked offline first. The Hamming healing, the syndrome-as-address, the 128 = 16·8 partition, and every sphere-packing identity in Instruments II–III are computed in your browser and independently verified in /research/perfect-codes/: hamming.mjs (the code built from its parity-check matrix, all 112 single errors healed, the radius-1 balls shown to partition F₂⁷ — 7/7), golay.mjs (the binary Golay codes constructed from a quadratic-residue matrix and pinned by their exact weight enumerators, self-duality, and the 2¹²·2048=2²³ perfection — 11/11), and census.mjs (the Hamming family, the ternary Golay built over F₃, the trivial codes, and the phantom's balancing arithmetic — 19/19).
Cited, not re-proved. The completeness of the census — that nothing outside this list can exist — is the van Lint–Tietäväinen theorem; we verify its arithmetic and the non-existence of the named phantoms but do not reprove the theorem itself. The Leech-lattice / M₂₄ remarks and the 2017 sphere-packing result are stated as context, with sources below. The checker reports possibility for codes over a finite field in the Hamming metric; over non-field alphabets and in other metrics the landscape differs.
Perfect codes are not the codes engineering actually uses — they're too rigid and too rare. Real systems (Reed–Solomon on discs and deep-space links, LDPC and turbo codes in your phone) trade perfection for flexibility and get closer to Shannon's limit on real channels. What's perfect about a perfect code is only the packing: zero wasted room. That mathematical perfection, and its near-total unavailability, is the subject here — not a claim about the best way to send a file.
Sources. R. W. Hamming, “Error Detecting and Error Correcting Codes,” Bell System Technical Journal 29(2):147–160, 1950 (the quoted recollection is from his later interviews/lectures). M. J. E. Golay, “Notes on Digital Coding,” Proceedings of the IRE 37:657, 1949 (a single page; the Golay codes). J. H. van Lint, “Nonexistence theorems for perfect error-correcting codes,” 1971, and A. Tietäväinen, “On the nonexistence of perfect codes over finite fields,” SIAM J. Appl. Math. 24:88–96, 1973 (the classification). S. P. Lloyd, “Binary block coding,” Bell System Technical Journal 36:517–535, 1957 (the necessary condition). The (90, 2⁷⁸, 5) phantom: a standard example of bound-feasible non-existence, excluded by the classification. M₂₄ / Leech lattice: J. H. Conway & N. J. A. Sloane, Sphere Packings, Lattices and Groups. The 24-dimensional optimum: Cohn, Kumar, Miller, Radchenko & Viazovska, “The sphere packing problem in dimension 24,” Annals of Mathematics 185:1017–1033, 2017 (following Viazovska's dimension-8 result the same year).