Perfect Codes: the Hamming and Golay Codes
Anchor (Master): van Lint 1999 *Introduction to Coding Theory* 3e Ch. 3-4, 6 (the binary [23,12,7] and ternary [11,6,5] Golay codes, weight enumerators, Lloyd's theorem, the van Lint-Tietäväinen classification); MacWilliams-Sloane 1977 *The Theory of Error-Correcting Codes* Ch. 6, 16, 20 (the Golay codes, the Mathieu groups, the 5-designs); Conway-Sloane 1988 *Sphere Packings, Lattices and Groups* (Springer) Ch. 10-11 (the Golay code, the Leech lattice, the Mathieu groups); Hamming 1950 *Bell System Tech. J.* 29; Golay 1949 *Proc. IRE* 37; Tietäväinen 1973 *SIAM J. Appl. Math.* 24; van Lint 1975 (the classification)
Intuition Beginner
A code spreads its messages out as a scattered handful of allowed strings, and decoding means snapping a corrupted string back to the nearest allowed one. Around each allowed string, picture a ball: all the strings you reach by flipping at most a fixed number of symbols. If the balls never overlap, decoding is unambiguous — a lightly damaged string lands in exactly one ball and you read off its centre. But the balls might leave gaps: strings that sit too far from every codeword to be repaired with confidence.
A perfect code is the case with no gaps and no overlaps. The balls fit together so snugly that they fill the whole space of strings, each string belonging to one ball and no string left over. Every possible received string is within the correcting radius of exactly one codeword. Nothing is wasted: the code packs the maximum number of messages that the correcting power allows, with the error-balls tiling the space the way identical tiles cover a floor.
Such flawless packings are rare. You might guess that for every length and every correcting radius there is some clever perfect code, but the truth is the opposite. Apart from a few unavoidable boring cases, only two families exist: the Hamming codes, which fix one error, and two lonely Golay codes discovered by Marcel Golay in a half-page note. These few are the only ways to tile string-space exactly. This unit builds them and explains why the list stops there.
Visual Beginner
Think of the space of all strings as a floor, and the error-ball around each codeword as a tile. A perfect code is a set of tiles that covers the floor with no gaps and no overlaps. A non-perfect code leaves bare patches between the tiles: strings the code cannot confidently repair.
| code | error-balls | leftover strings | perfect? |
|---|---|---|---|
| repetition , radius | yes | ||
| Hamming length , radius | yes | ||
| a random length- code, radius | fewer than | some left over | no |
The table counts strings. The space of length- binary strings holds points; a radius- ball holds points; and balls times points each is exactly . The fit is perfect — no point is missed, none is double-covered.
Worked example Beginner
Take the binary repetition code that sends each bit three times: the codewords are and , living among the strings of length . Check by counting that this code is perfect with correcting radius .
Step 1. Count the strings. Length- binary strings number . List them: .
Step 2. Count one error-ball. The ball of radius around holds itself plus the three strings one flip away: . That is strings. The ball around likewise holds — another .
Step 3. Check the tiling. The two balls together list and — all strings, each appearing once. The balls do not overlap and leave nothing out.
Step 4. Confirm the count. Two codewords times four strings per ball is , exactly the number of strings. The sphere-packing count comes out equal, which is the signature of a perfect code.
What this tells us: the repetition code wastes nothing — every length- string is one flip from exactly one of the two codewords, so every single error is repaired and no string is ever ambiguous. This same balance, scaled up, defines the Hamming and Golay codes.
Check your understanding Beginner
Formal definition Intermediate+
Throughout, is the finite field with elements (its structure is developed in 21.02.01; here it is applied), a prime power, and the space of length- words with the Hamming metric of 40.06.06. A code has minimum distance and corrects errors. The volume of a Hamming ball of radius is .
Definition (perfect code). A code of minimum distance is perfect if the closed Hamming balls of radius about its codewords partition ; equivalently, it meets the sphere-packing bound with equality, $$ |C| \cdot V_q(n, e) = q^n. $$ The elementary perfect codes are the whole-space codes (), the codes with a single codeword, and the binary repetition codes of odd length . A perfect code that is none of these is called a genuine (nonelementary) perfect code.
Definition (Hamming code). Fix and let , the number of one-dimensional subspaces of . The -ary Hamming code is the code whose parity-check matrix has columns one nonzero representative from each one-dimensional subspace, so that no two columns are scalar multiples of one another. For this lists all nonzero binary columns of length , giving the code.
Definition (simplex / dual code). The dual is the simplex code , an code whose every nonzero codeword has weight ; it is equidistant, all nonzero codewords pairwise at distance . Its generator matrix is the parity-check matrix of the Hamming code.
Definition (Golay codes). The binary Golay code is the cyclic code generated by a degree- factor of over (the construction is shared with the cyclic-code theory co-produced in 40.06.08). Its extension , adjoining an overall parity check, is the self-dual code. The ternary Golay code is the cyclic code from a factor of over , with extension , the self-dual code.
Counterexamples to common slips Intermediate+
Perfect is not the same as MDS. A perfect code meets the sphere-packing (volume) bound; an MDS code meets the Singleton (rank) bound. The Hamming code is perfect but not MDS, and a Reed-Solomon code is MDS but rarely perfect. The two extremal conditions are independent.
Hamming codes are defined by the columns of , not by a fixed generator. Any matrix with one nonzero representative per one-dimensional subspace gives a Hamming code; different choices yield permutation-equivalent codes with the same parameters. Listing all nonzero columns (not up to scalars) is correct only over , where each one-dimensional subspace has a unique nonzero vector.
The Golay code length is , not . The perfect code is with , correcting errors. Its extension has and is not perfect — it is even-weight and self-dual, valued for its automorphism group and design, not for tiling.
" is the only ternary perfect length." Only the ternary Golay code and the elementary ternary codes are perfect over . Length alone does not make a code perfect; the parameters must solve the sphere-packing equation, and over only does so nonelementarily.
Key theorem with proof Intermediate+
The defining fact about the Hamming code is that it tiles the space: every word is within distance one of a unique codeword. This follows from the column structure of the parity-check matrix.
Theorem (Hamming codes are perfect single-error-correcting codes). For and , the code has parameters , corrects one error, and is perfect: $$ q^{n-m} \cdot \big(1 + n(q-1)\big) = q^n. $$
Proof. The parity-check matrix is , its columns the representatives of the one-dimensional subspaces of , no two scalar-proportional. By the parity-check distance criterion of 40.06.06, the minimum distance is the least number of linearly dependent columns. No single column is zero, so . No two columns are dependent, since dependence of two columns means one is a scalar multiple of the other, excluded by construction; so . But some three columns are dependent: pick distinct one-dimensional subspaces and find a dependence — for instance over three columns with exist because the sum of two distinct nonzero vectors is a third nonzero vector, present as a column. Hence and .
The dimension is , since has rank (its columns span ). For perfection, the radius- ball has volume , and $$ |C| \cdot V_q(n,1) = q^{n-m}\big(1 + n(q-1)\big) = q^{n-m}\big(1 + (q^m - 1)\big) = q^{n-m}\cdot q^m = q^n, $$ using . Equality in the sphere-packing bound is perfection. Concretely, decoding is immediate: a received word has syndrome , which is either (then ) or a nonzero vector equal to a scalar multiple of exactly one column; subtracting in coordinate corrects the single error.
Bridge. This theorem builds toward the whole classification by pinning down the smallest genuine perfect codes — the single-error-correcting Hamming family — and it appears again in the master tier as the case of Lloyd's theorem, where the Lloyd polynomial has its one root at , exactly the weight of every simplex codeword. The foundational reason the count is exact is that the nonzero syndromes biject with the one-dimensional error patterns: nonzero syndromes match weight-one errors, and this is exactly the equality . This is dual to the simplex code, whose equidistance is the MacWilliams transform of the Hamming weight enumerator; the central insight — that perfection is a bijection between syndromes and correctable error patterns — generalises to the Golay codes, where the radius- balls biject with the binary syndromes. Putting these together, a perfect code is precisely a code whose syndrome map is a bijection from cosets to correctable errors, and the classification asks for which parameters such a bijection can exist.
Exercises Intermediate+
Advanced results Master
The Hamming codes settle the single-error case; the Golay codes are the only further genuine perfect codes, and their internal structure — weight enumerators, automorphism groups, and the designs they hold — places them at the centre of finite group theory. The results below trace those threads and close with the classification.
Theorem 1 (the binary Golay code and its weight enumerator). The binary Golay code is the cyclic code generated by either irreducible factor of over , each of degree ; equivalently it is the quadratic-residue code of length . Its extension is the self-dual doubly-even code with weight enumerator $$ W_{\mathcal{G}{24}}(x,y) = x^{24} + 759, x^{16}y^8 + 2576, x^{12}y^{12} + 759, x^8 y^{16} + y^{24}, $$ the unique self-dual doubly-even code. Puncturing one coordinate returns , whose weight distribution has , , , $A{11} = 1288A_{12} = 1288A_{15} = 506A_{16} = 253A_{23} = 1$ [MacWilliams-Sloane Ch. 6].
Theorem 2 (the ternary Golay code). The ternary Golay code is the cyclic code from a degree- factor of over ; its extension is the self-dual code with weight enumerator $$ W_{\mathcal{G}{12}}(x,y) = x^{12} + 264, x^6 y^6 + 440, x^3 y^9 + 24, y^{12}, $$ the codewords of weight supporting a Steiner system [van Lint 1999 Ch. 4]. An equivalent construction borders the circulant of quadratic residues modulo , tying $\mathcal{G}{12}12\pm 1$ adjacency pattern reproduce the same self-dual code.
Theorem 3 (Mathieu groups as automorphism groups). The automorphism group of acting on the coordinates is the Mathieu group , a sporadic simple group of order , -transitive on points; the stabiliser of a coordinate is , -transitive on points and equal to . The ternary has automorphism group , with sporadic simple of order and -transitive on points; the coordinate stabiliser is . These four Mathieu groups are the first sporadic simple groups discovered (Mathieu, 1861-1873), realised here as code automorphisms [MacWilliams-Sloane Ch. 16].
Theorem 4 (the -designs; Assmus-Mattson). By the Assmus-Mattson theorem (proved in the co-produced cyclic-code unit 40.06.08), the supports of the weight- codewords of form a Steiner system — the octads — a - design; the weight- codewords give a - design. The weight- codewords of form a Steiner system , a - design of hexads. These remain among the very few known genuinely -transitive designs, and their automorphism groups are exactly the Mathieu groups of Theorem 3. The Steiner-system viewpoint connects directly to 40.06.04, where and are the apex examples.
Theorem 5 (Lloyd's theorem). If a perfect -error-correcting code of length over exists, then the Lloyd polynomial $$ L_e(x) = \sum_{i=0}^{e} (-1)^i (q-1)^{e-i} \binom{x-1}{i}\binom{n-x}{e-i} $$ has distinct integer roots in [Lloyd 1957]. The roots are the nonzero eigenvalues' index set of the Hamming association scheme that lie in the radius- Lloyd spectrum; is, up to normalisation, the Krawtchouk polynomial , so the condition says of the Krawtchouk values vanish at integer arguments — a severe arithmetic restriction.
Theorem 6 (van Lint-Tietäväinen classification). Over any finite field , a perfect -error-correcting code with and length has one of the following parameter sets: a Hamming code ; the binary Golay code ; the ternary Golay code ; or a binary repetition code of odd length. No other parameters admit a perfect code [Tietäväinen 1973]. The proof combines Lloyd's theorem — which forces to have integer roots — with a delicate Diophantine analysis (using lower bounds on the roots and a study of ) eliminating every remaining parameter set.
Synthesis. Putting these together, perfection is a single arithmetic miracle read across three registers, and this is exactly the content of the classification. The sphere-packing equality is the foundational reason a perfect code exists at all: it demands that the ball volume divide , and Lloyd's theorem sharpens this to the statement that the Krawtchouk polynomial must have integer roots in the admissible range — the central insight that converts a packing problem into a question about the zeros of orthogonal polynomials on the Hamming scheme. This is dual, in the precise MacWilliams sense, to the simplex and Golay weight enumerators: the equidistance of the simplex code is the spectral shadow of the Hamming code's perfection, and the doubly-even self-dual enumerator of is the spectral shadow of the Golay packing. The classification is exactly the assertion that this miracle happens only at the Hamming parameters, at and , and at the elementary repetition lengths — the Golay arithmetic and its ternary twin being isolated coincidences. The bridge from these finite identities to the wider mathematics is the automorphism groups: the same coordinate symmetries that preserve the packing generalise into the Mathieu sporadic simple groups and, through the design and the Leech lattice, into the Conway groups and the monstrous moonshine that organises the largest sporadic group.
Full proof set Master
Proposition 1 (Hamming parameters and perfectness). is an perfect code with .
Proof. The columns of are representatives of the distinct one-dimensional subspaces of ; their number is , the count of nonzero vectors divided by the scalars identifying each subspace. No column is zero and no two are proportional, so by the distance criterion of 40.06.06 ; and three proportional-free columns satisfying a dependence exist (the span of any two distinct one-dimensional subspaces is two-dimensional and contains a third subspace, whose representative is a third column lying in that span), giving . Rank as its columns span , so . Then , the sphere-packing equality, so is perfect.
Proposition 2 (simplex code is equidistant of weight ). Every nonzero codeword of has weight , and any two distinct codewords are at distance .
Proof. A nonzero codeword is with , coordinate where ranges over one representative per one-dimensional subspace. The functional is a nonzero linear form, vanishing on a hyperplane of vectors. Among the nonzero vectors, those in the kernel number , partitioned into one-dimensional subspaces, each contributing a zero coordinate of . So has zero coordinates and the remaining coordinates nonzero. Thus for all nonzero . By linearity for distinct codewords, since is another nonzero codeword.
Proposition 3 (perfect codes meet sphere-packing with equality iff balls tile). A code of minimum distance satisfies iff its radius- balls partition .
Proof. The radius- balls about distinct codewords are pairwise disjoint: a common point of , gives . Each ball has points. Their disjoint union has points inside , so ; equality holds iff the union is all of , i.e. the balls partition the space.
Proposition 4 (Lloyd necessary condition, case). A perfect single-error-correcting code of length over has vanishing at exactly one integer ; for the Hamming code .
Proof. For the Lloyd polynomial is . Setting gives , so . For the Hamming code , hence and , an integer in range — the common weight of the simplex codewords from Proposition 2. The single integer root certifies the parameters against Lloyd's theorem. The general- statement, that has distinct integer roots, follows from the eigenvalue structure of the Hamming association scheme: a perfect code is a completely regular code whose outer distribution is governed by the scheme's eigenvalues, and the roots are the eigenvalue indices where the dual degree vanishes [Lloyd 1957].
Proposition 5 (uniqueness of the binary Golay code from its weight enumerator). Any binary self-dual doubly-even code has the weight enumerator of , and there is exactly one such code up to equivalence.
Proof. Self-duality forces (the MacWilliams identity of 40.06.06 applied with ), and double-evenness forces invariant under . By Gleason's theorem the ring of such invariant weight enumerators of degree is spanned by and , where is the Hamming-extended code; imposing (minimum distance ) pins down the coefficients uniquely to . That a code with this enumerator exists and is unique is verified by constructing (e.g. as the extended quadratic-residue code mod ) and checking that the octads form an , a configuration rigid enough that its automorphism group acts transitively and forces equivalence of any two realisations [MacWilliams-Sloane Ch. 6, 20].
Connections Master
The perfect-code condition is the equality case of the sphere-packing (Hamming) bound proved in
40.06.06: that unit supplies the inequality and the parity-check distance criterion, and this unit characterises exactly when equality holds. The foundational reason the Hamming codes are perfect is the bijection between the nonzero syndromes and the weight-one error patterns, which is the same column-counting argument that gives the distance criterion there.The arithmetic of the alphabet rests on the finite-field theory of
21.02.01: the Hamming code's columns enumerate the projective points , the Golay codes are built from factorisations of over and over (quadratic-residue codes), and the residue-class arithmetic modulo and that singles out these two lengths is finite-field number theory. This is dual to the cyclic-code structure, where the same factorisations reappear as generator polynomials.The co-produced unit
40.06.08on cyclic codes and the Assmus-Mattson theorem supplies the construction of both Golay codes as cyclic (quadratic-residue) codes and proves that their fixed-weight codewords hold -designs; this unit uses those designs as the bridge to the Mathieu groups. The Assmus-Mattson machinery is exactly what turns the weight enumerator computed here into the Steiner systems and .The co-produced unit
40.06.04on Steiner systems is where and live as design-theoretic objects: the Golay codes produce these Steiner systems (the octads and hexads), and conversely a Steiner system reconstructs . The two units describe the same combinatorial object from the coding and the design sides, with the Mathieu groups as the common automorphism group.
Historical & philosophical context Master
The single-error-correcting codes are Richard Hamming's, published in 1950 [Hamming 1950] after his weekend frustration with relay-computer failures; the code is the prototype, and the general family carries his name. The sphere-packing bound he introduced makes the perfectness immediate, and the codes are the smallest genuine solutions of the packing equation.
The Golay codes appeared a year earlier, in Marcel Golay's 1949 half-page note in the Proceedings of the IRE [Golay 1949] — one of the most information-dense pages in mathematics. Golay observed that the binomial sum permits a binary triple-error-correcting perfect code of length , and that a ternary analogue exists at length , and he exhibited both. The codes' automorphism groups turned out to be the Mathieu groups, discovered by Émile Mathieu in 1861 and 1873 as multiply-transitive permutation groups, and the first of the sporadic simple groups in the eventual classification.
The completeness of the list was conjectured early and proved in stages. Shen Pin Lloyd gave his necessary condition in 1957 [Lloyd 1957], reducing perfect codes to an integer-root problem for a Krawtchouk polynomial. Aimo Tietäväinen, with Jacobus van Lint, closed the classification over finite fields in 1973 [Tietäväinen 1973]: the Hamming codes, the two Golay codes, and the binary repetition codes are the only perfect codes over fields. Over arbitrary alphabets the question stays open in the unequal-error-protection and mixed-alphabet settings, and the design later seeded Conway's construction of the Leech lattice and the larger sporadic groups.
Bibliography Master
@article{hamming1950,
author = {Hamming, Richard W.},
title = {Error detecting and error correcting codes},
journal = {Bell System Technical Journal},
volume = {29},
number = {2},
year = {1950},
pages = {147--160}
}
@article{golay1949,
author = {Golay, Marcel J. E.},
title = {Notes on digital coding},
journal = {Proceedings of the IRE},
volume = {37},
year = {1949},
pages = {657}
}
@article{lloyd1957,
author = {Lloyd, Shen Pin},
title = {Binary block coding},
journal = {Bell System Technical Journal},
volume = {36},
year = {1957},
pages = {517--535}
}
@article{tietavainen1973,
author = {Tiet\"{a}v\"{a}inen, Aimo},
title = {On the nonexistence of perfect codes over finite fields},
journal = {SIAM Journal on Applied Mathematics},
volume = {24},
number = {1},
year = {1973},
pages = {88--96}
}
@article{vanlint1971survey,
author = {van Lint, Jacobus H.},
title = {Nonexistence theorems for perfect error-correcting codes},
journal = {Computers in Algebra and Number Theory (SIAM-AMS Proceedings)},
volume = {4},
year = {1971},
pages = {89--95}
}
@article{mathieu1873,
author = {Mathieu, \'{E}mile},
title = {Sur la fonction cinq fois transitive de 24 quantit\'{e}s},
journal = {Journal de Math\'{e}matiques Pures et Appliqu\'{e}es},
volume = {18},
year = {1873},
pages = {25--46}
}
@book{vanlint1999coding,
author = {van Lint, Jacobus H.},
title = {Introduction to Coding Theory},
series = {Graduate Texts in Mathematics},
volume = {86},
edition = {3rd},
publisher = {Springer},
year = {1999}
}
@book{macwilliamssloane1977,
author = {MacWilliams, F. Jessie and Sloane, Neil J. A.},
title = {The Theory of Error-Correcting Codes},
publisher = {North-Holland},
year = {1977}
}
@book{conwaysloane1988,
author = {Conway, John H. and Sloane, Neil J. A.},
title = {Sphere Packings, Lattices and Groups},
publisher = {Springer},
year = {1988}
}
@book{vanlintwilson2001,
author = {van Lint, Jacobus H. and Wilson, Richard M.},
title = {A Course in Combinatorics},
edition = {2nd},
publisher = {Cambridge University Press},
year = {2001}
}