On this page
The strings 1011001 and 1001011 differ in two places, the third and the sixth. That count, their Hamming distance, decides what an error-correcting code can do.
What is Hamming distance?
The Hamming distance between two strings of equal length is the number of positions at which they differ (Wikipedia: Hamming distance). It is named after Richard Hamming, whose paper "Error Detecting and Error Correcting Codes" appeared in the Bell System Technical Journal in April 1950 (Hamming, 1950).
A code's minimum distance d is the smallest Hamming distance between any two of its codewords.
How many errors can a code with minimum distance d detect and correct?
A code with minimum distance d can detect up to d − 1 errors and correct up to ⌊(d − 1)/2⌋ errors (Wikipedia: error detection and correction).
Detection: fewer than d flips can never turn one codeword into another, so the receiver sees a word outside the code. Correction: draw a ball of radius t (every word within distance t) around each codeword. If 2t + 1 ≤ d, no two balls overlap, so a word with at most t errors sits in one ball and decodes to its centre.
d = 2 (one parity bit): detects 1 error, corrects none.
d = 3: detects 2, corrects 1.
d = 7: detects 6, corrects 3.
What is the Hamming bound?
The Hamming bound, also called the sphere-packing bound, says a q-ary code of length n that corrects t errors has at most q^n ÷ [C(n,0) + C(n,1)(q − 1) + … + C(n,t)(q − 1)^t] codewords (Wikipedia: Hamming bound). The bracket counts the words in one ball: choose which k positions go wrong, then a wrong symbol for each. The balls do not overlap and fit inside the q^n possible words, so codewords × ball size ≤ q^n.
How many codewords can a 7-bit code hold?
With q = 2 there are 2^7 = 128 words, and a ball is a sum of binomial coefficients (Wikipedia: Hamming bound).
Correct one error (d = 3, t = 1). Ball size 1 + 7 = 8. Bound 128 ÷ 8 = 16 codewords.
Correct two errors (d = 5, t = 2). Ball size 1 + 7 + 21 = 29. Bound 128 ÷ 29 ≈ 4.4, so at most 4.
Correct three errors (d = 7, t = 3). Ball size 1 + 7 + 21 + 35 = 64. Bound 128 ÷ 64 = 2.
Case 1 is met exactly. Hamming's (7,4) code adds three parity bits to four data bits, giving 2^4 = 16 codewords with minimum distance 3 (Wikipedia: Hamming(7,4)). Sixteen balls of 8 fill all 128 words. Case 3 is met by {0000000, 1111111}.
Case 2 is not met. For any three binary words a, b, c, each position adds 0 or 2 to d(a,b) + d(b,c) + d(a,c), never 3, so the sum is at most 14. Three codewords pairwise at distance 5 or more would need 15. The true maximum is 2, not 4: the bound is a ceiling, not a promise.
What are perfect codes?
A code that meets the Hamming bound with equality is a perfect code: its balls tile the whole space (Wikipedia: Hamming bound). Binary repetition codes of odd length are trivial examples.
The binary Golay code has length 23, 12 data bits and minimum distance 7 (Wikipedia: binary Golay code), so t = 3. Check it: 1 + 23 + 253 + 1771 = 2048 = 2^11, and 2^23 ÷ 2^11 = 2^12, exactly its number of codewords. Marcel Golay published it in a one-page note in June 1949 (Proc. IRE 37, p. 657).
In 1973 Aimo Tietäväinen proved there are no unknown perfect error-correcting codes over finite fields (Tietäväinen, 1973): any non-trivial one has the parameters of a Hamming or Golay code.
What does the Singleton bound add?
The Singleton bound says a q-ary code of length n and minimum distance d has at most q^(n − d + 1) codewords (Wikipedia: Singleton bound). Proof: delete the first d − 1 symbols of every codeword; the shortened words are still all different, and only q^(n − d + 1) exist. It is named after Richard Singleton's 1964 paper (Singleton, 1964), though D. D. Joshi proved it earlier, in 1958 (Joshi, 1958).
For 7-bit codes with d = 3 it allows 2^5 = 32 codewords, twice the Hamming bound's 16, so sphere packing is sharper here. Linear codes meeting it are called MDS codes; Reed–Solomon codes are examples.
If binomial sums still feel loose, the Fermi Concept Library covers every concept in mathematics and computing, and the Fermi Problem Library has a step-by-step solver that explains the reasoning. Related reads: Shannon entropy in bits, finite fields built by hand and the kissing number packing problem.



