If the channel introduces errors, how do you protect the message? The answer is to add structured redundancy - an error-correcting code that allows the receiver to detect and correct errors deterministically. The mathematical foundation is Hamming distance, introduced by Richard Hamming in 1950: the distance between two binary strings is the number of positions where they differ. Two codewords at distance at least 2t + 1 can correct up to t errors - the receiver chooses the codeword nearest to the received message (minimum-distance decoding). This article introduces theoretical bounds that limit the efficiency of every code: the Hamming bound (sphere-packing, maximum number of codewords) and the Singleton bound (relationship between length, dimension, and distance). Understanding these bounds is crucial to recognize when a code is perfect or optimal, and where real codes (Hamming, Reed-Solomon, turbo) stand in this theoretical landscape. The central theme is the trade-off between redundancy and correction: each bit of redundancy allows more errors to be corrected, but reduces coding rate - and Shannon's bound from the previous lesson defines the ultimate limit of this trade-off.
Historical context and formalization
Richard Hamming (1950) develops the concept of distance and perfect code to solve a practical problem: the Bell Model II computer introduced errors in data stored on magnetic drums. Hamming creates the Hamming [7,4] code: 4 information bits + 3 parity bits, which corrects 1 arbitrary error. The key discovery is that the minimum distance between two codewords determines how many errors can be corrected. In the 1950s and 1960s, Plotkin, Singleton, and others develop theoretical bounds that limit the efficiency of any code. In 1960, Irving Reed and Gustavo Solomon invent Reed-Solomon (RS) codes, which achieve the Singleton bound and are used today in every critical system (backup, space communications, QR codes, video streaming). These codes represent the meeting point between pure theory and practical application.
Article outline
- Hamming distance: definition and geometric interpretation
- Hamming spheres and number of codewords
- Linear block codes: generator and parity-check matrices
- The Hamming bound (sphere-packing bound)
- The Singleton bound and MDS codes (Maximum Distance Separable)
- Concrete examples: Hamming [7,4], Reed-Solomon [255,223]
Hamming distance: definition and geometric interpretation
The Hamming distance between two binary strings of length n, denoted x and y, is the number of positions where they differ:
d_H(x, y) = |{i : x_i ≠ y_i}|
Example: x = 1011, y = 1101. They differ in positions 1 and 3, so d_H(x, y) = 2.
Hamming distance satisfies metric properties:
- Non-negativity:
d_H(x, y) ≥ 0, with equality iffx = y - Symmetry:
d_H(x, y) = d_H(y, x) - Triangle inequality:
d_H(x, z) ≤ d_H(x, y) + d_H(y, z)
Geometric interpretation: the space of all binary strings of length n has 2^n points. A "sphere" of radius t around a point c contains all points at distance at most t from c. The number of strings at distance exactly j is binom(n, j) (choose which j positions to flip), so the total number of strings in a sphere of radius t is:
V(n, t) = sum_{j=0}^{t} binom(n, j)
This is the Hamming sphere - the "volume" measures how many strings the code can correct.
Hamming spheres and number of codewords
If a code has minimum distance d_min = 2t + 1 (the minimum distance between any two codewords is 2t + 1), then each codeword can correct up to t errors. Why? Because if you receive a string y at distance ≤ t from a codeword c, then y is not at distance ≤ t from any other codeword c' (otherwise, by the triangle inequality, d_H(c, c') ≤ d_H(c, y) + d_H(y, c') ≤ 2t, contradicting d_min = 2t + 1). So minimum-distance decoding - choose the nearest codeword - always corrects the error.
If the code has M codewords (information k = log2(M) bits) and each sphere of radius t has volume V(n, t), then the M spheres cannot overlap:
M * V(n, t) ≤ 2^n
Rearranging: M ≤ 2^n / V(n, t), so the number of codewords is limited by the ratio of total space to sphere volume. This gives the Hamming bound we address next.
Linear block codes: generator and parity-check matrices
A linear [n, k] code is a linear subspace of F_2^n (binary n-dimensional) of dimension k. It contains exactly 2^k codewords. Encoding multiplies the message (k-dimensional vector) by a generator matrix G (k x n):
c = m * G
where m is the message, c is the codeword, and the product is in linear algebra over F_2 (modulo 2).
Decoding uses a parity-check matrix H ((n-k) x n) such that G * H^T = 0 (all codewords satisfy c * H^T = 0):
r * H^T = syndrome s = (codeword has errors) ? non-zero : zero
If s ≠ 0, the received r has errors; the syndrome identifies which bit was flipped (in perfect codes like Hamming [7,4]).
The Hamming bound (sphere-packing bound)
The Hamming bound (also called sphere-packing bound or Hamming bound) states: for an [n, k] code correcting t errors,
2^k ≤ 2^n / V(n, t) = 2^n / sum_{j=0}^{t} binom(n, j)
Rearranging logarithmically:
k ≤ n - log2(sum_{j=0}^{t} binom(n, j))
A code is perfect if it achieves equality: then Hamming spheres cover F_2^n exactly without overlap. Hamming [7,4] is perfect: 2^4 = 16 codewords, radius t = 1, sphere volume V(7,1) = 1 + 7 = 8, total 16 * 8 = 2^7 = 128 - perfect coverage.
The Singleton bound and MDS codes
The Singleton bound states that the minimum distance d_min of an [n, k] code satisfies:
d_min ≤ n - k + 1
A code reaches the bound if d_min = n - k + 1 - it is called Maximum Distance Separable (MDS). MDS codes are optimal for the trade-off between distance and coding rate R = k/n.
Reed-Solomon codes are MDS: for length n = 2^m - 1 and dimension k, they have d_min = n - k + 1. Example: Reed-Solomon [255, 223] has d_min = 255 - 223 + 1 = 33, corrects up to t = 16 errors and burst radius (contiguous errors) up to 16 bytes.
Bound comparison: Hamming limits the number of codewords (space absorption), while Singleton limits distance (correction efficiency). For Hamming [7,4]: n - k + 1 = 7 - 4 + 1 = 4, but actual distance is 3 (one error, not Singleton-optimal). For Reed-Solomon [255, 223]: Singleton bound is reached, the code is perfect for that trade-off.
Why t = floor((d-1)/2): geometric reasoning
The formula for the number of correctable errors t = floor((d_min - 1) / 2) emerges from the geometry of Hamming spheres. Imagine binary space at n dimensions as a grid: each point is a string of n bits, distance between two points is the number of coordinates where they differ (Hamming distance).
A sphere of radius t around a codeword c is the set of all strings at distance ≤ t from c. If the channel introduces up to t errors, the received string r falls inside the sphere around c.
Condition for correcting t errors: the spheres of radius t around two different codewords must NOT overlap. If two codewords c and c' are at distance d_min, the minimum distance between centers is d_min. Spheres of radius t around each one do not overlap if:
t + t < d_min → 2t < d_min → t < d_min / 2
Since t must be an integer, t = floor((d_min - 1) / 2). Visualization: if d_min = 5, then t = 2. Two codewords at distance 5 have non-overlapping spheres of radius 2: distance between centers is 5, and 2+2 = 4 < 5 ✓.
Detection limit: If instead you only want to detect errors (not correct them), you just need a received string at distance ≤ d_min - 1 from a codeword to not be another codeword. Condition: d_min ≥ 2 (distance at least 2). So detection is easier than correction: you can detect d_min - 1 errors, but correct only floor((d_min - 1) / 2).
Perfect codes and the rarity of codewords
A code is perfect if it achieves equality in the Hamming bound: the spheres of radius t around codewords cover exactly space F_2^n without overlap. Every received string is at distance ≤ t from exactly one codeword - minimum-distance decoding is always correct, without ambiguity.
Perfect codes are extraordinarily rare. The only binary perfect codes are:
- Hamming codes [2^m - 1, 2^m - m - 1]: correct 1 error (t=1). Examples: [7,4], [15,11], [31,26]. Proven perfect by Shannon.
- Golay code [23,12]: corrects 3 errors (t=3). Used in NASA space communications (Voyager).
- Trivial codes: the repetition code [n, 1] (transmit message n times), identity code [n, n] (no redundancy).
No others exist. This means: beyond Hamming, Golay, and trivial codes, EVERY binary code is "sub-perfect" - wastes space, has overlapping spheres. Most practical codes (Reed-Solomon, turbo, LDPC) sacrifice perfection for other benefits: large distance, fast decoding, good practical performance under noise.
Concrete examples: Hamming [7,4], Reed-Solomon [255,223]
Hamming [7,4]: full construction
Hamming [7,4] encodes 4 information bits into 7 codeword bits (3 parity bits). Construction with generator matrix G (4 × 7):
G = [1 0 0 0 1 1 0]
[0 1 0 0 1 0 1]
[0 0 1 0 0 1 1]
[0 0 0 1 1 1 1]
This is in systematic form: the first 4 columns are identity (information bits), the last 3 are parity bits computed from the first 4.
Complete numerical example - Encoding: Suppose you encode message m = [1, 0, 1, 0] (4 information bits).
c = m * G = [1, 0, 1, 0] * G
= 1*(1,0,0,0,1,1,0) + 0*(0,1,0,0,1,0,1) + 1*(0,0,1,0,0,1,1) + 0*(0,0,0,1,1,1,1)
= (1,0,0,0,1,1,0) + (0,0,1,0,0,1,1)
= (1,0,1,0,1,0,1) (modulo 2: 1+1=0 at position 5)
Transmitted codeword: c = 1010101 (7 bits).
Decoding - no errors: If receiver gets r = 1010101 (identical to c), compute syndrome using parity-check matrix H:
H = [1 1 0 1 0 0 0]
[1 0 1 1 0 1 0]
[0 1 1 1 0 0 1]
Syndrome: s = r * H^T (mod 2). If r = c, syndrome is zero (valid codeword).
Decoding - with single error: Suppose channel introduces error at position 3: receive r = 1011101 (the 0 at position 3 becomes 1). Compute syndrome:
s = r * H^T = 1011101 * [1 1 0]^T
[1 0 1]^T
[0 1 1]^T
[1 1 1]^T
[0 0 0]^T
[0 1 0]^T
[0 0 1]^T
= [1*1 + 0*1 + 1*0 + 1*1 + 1*0 + 0*0 + 1*0] mod 2 = 0 (first component)
= [1*1 + 0*0 + 1*1 + 1*1 + 1*0 + 0*1 + 1*0] mod 2 = 1 (second component)
= [1*0 + 0*1 + 1*1 + 1*1 + 1*0 + 0*0 + 1*1] mod 2 = 1 (third component)
→ s = [0, 1, 1] = 3 (binary)
Syndrome 3 indicates error at position 3. Flip bit 3 of r: r' = 1010101 (corrected).
Why syndrome identifies position: Each column of matrix H is a unique binary number from 0 to 7. If channel changes the bit at position j, the syndrome is exactly the binary number of column j of H. This is the "magic" of Hamming code: syndrome is the error's "signature".
Hamming [7,4] properties: Minimum distance d_min = 3 (corrects 1 error, detects 2). It is perfect: the 2^4 = 16 spheres of radius 1 cover exactly 2^7 = 128 strings (16 * 8 = 128). Coding rate R = 4/7 ≈ 0.571 (57% redundancy).
Reed-Solomon [255, 223]: Used in space transmissions (NASA), magnetic backups, QR codes. Operates on 256-symbol alphabet (1 byte). Corrects up to 16 byte errors (not bits). Generator matrix is built over extension field (polynomials over GF(2^8)), not ordinary F_2. Implementation: Fast FFT (FFT-based polynomial multiplication), cost O(n log n).
Trade-off reasoning
I chose to present the Hamming bound before the Singleton bound because the first is intuitive (geometric: non-overlapping spheres) and the second is more algebraic-abstract. Real codes operate between these bounds: Hamming [7,4] is perfect for Hamming but not MDS; Reed-Solomon is MDS but not perfect for Hamming (spheres overlap). Code choice depends on application: if space is limited (memory, bandwidth) and you want maximum distance, use MDS (Reed-Solomon); if you want fast decoding (syndrome decoding), use perfect (Hamming).
Advanced connections
Detection vs. Correction in networks: In digital networks, it is not always best to correct every error locally. An alternative strategy: detect the error (with a code of minimum distance d ≥ 2), then request packet retransmission (ARQ - Automatic Repeat reQuest). Benefits: (i) code has less redundancy (requires only d ≥ 2, not d = 2t+1); (ii) receiver has no computational cost of correction. Downsides: (i) latency increases (waiting for retransmission); (ii) extra bandwidth for feedback. In practice: space communications (far, one-way) use correction (retransmission not possible); terrestrial low-latency networks (Ethernet, Wi-Fi) use detection + ARQ. The trade-off is between static redundancy (correction) and dynamic redundancy (retransmission).
Turbo codes and LDPC: Achieve performance near Shannon capacity via iterative decoding. Syndrome becomes the key to factor graph. Not geometric like Hamming, but algebraic and randomized.
BCH (Bose-Chaudhuri-Hocquenghem): Extension of Hamming codes that corrects multiple errors (not just 1). Used in flash memory (SSD), optical disks.
Concatenated codes: Combine two codes (e.g., outer Reed-Solomon + inner convolutional) to reach performance threshold with manageable complexity.
Quantum error correction: Extends Hamming theory to qubits. Distance remains the critical parameter, but redundancy is over quantum states.
Pitfalls and common errors
- Confusing minimum distance with number of correctable errors. If
d_min = 5, correctt = (d_min - 1) / 2 = 2errors, not 5. The exact formula ist = floor((d_min - 1) / 2). - Thinking Hamming bound is always reached. Only perfect codes reach it (Hamming, Golay, trivial). Most codes are "sub-perfect".
- Applying Singleton bound to non-binary codes incorrectly. The bound holds for any alphabet; for q-ary alphabet,
d_min ≤ n - k + 1remains exact. - Forgetting modulo 2 in boolean computations. Linear algebra over
F_2is not ordinary algebra:1 + 1 = 0. - Confusing coding rate with channel capacity. Rate
R = k/nis the fraction of information bits; capacity C is the maximum reliable rate (from second theorem).R < Cis necessary for reliability, but not sufficient without coding.
Advanced exercises
- Hamming sphere: Compute the volume of sphere of radius 2 for n = 10. (Answer: binom(10,0) + binom(10,1) + binom(10,2) = 1 + 10 + 45 = 56)
- Hamming [7,4] decoding: Receive r = 1010101. Compute syndrome s = r * H^T (using H given above). What is the error position?
- Hamming bound: A binary code must correct 2 errors (t = 2) on length n = 15. What is the maximum k for which Hamming bound is satisfied?
- MDS and Singleton: Is a code [20, 15] MDS? (Exact: d_min = 20 - 15 + 1 = 6, which is the Singleton bound.)
- Reed-Solomon implementation (simulation): Use Python library `reedsolo` (or similar) to encode a message, introduce errors, decode, and measure correction capacity.
Essential bibliography
- T. M. Cover, J. A. Thomas, Elements of Information Theory, 2nd ed., Wiley, 2006. (Chapters 10-13: Block Codes)
- C. E. Shannon, "A Mathematical Theory of Communication", Bell System Technical Journal, 1948.
- R. Hamming, "Error Detecting and Error Correcting Codes", Bell System Technical Journal, 1950.
- S. Lin, D. J. Costello, Error Control Coding: Fundamentals and Applications, 2nd ed., Pearson, 2004. (Industry standard)
- I. Reed, G. Solomon, "Polynomial Codes over Certain Finite Fields", Journal of the Society for Industrial and Applied Mathematics, 1960.
- B. Vasic, A. Gabidulin, "Classical and Quantum Error Correction Codes", in Handbook of Coding Theory, Elsevier, 1998.
Technical prerequisites
- Linear algebra over finite fields
F_2andGF(2^m)(optional) - Polynomials and arithmetic modulo primes (for Reed-Solomon)
- Combinatorics and binomial coefficients
- Discrete probability (from first article in series)
- Python: NumPy for linear algebra, dedicated libraries (reedsolo, galois)
Related resources and internal links
- Information Theory Series Index
- Previous: Noisy channels and Shannon capacity
- Next: Lossy compression and rate-distortion
- Related: Entropy and mutual information
- University Section - Lecture Notes and Educational Articles
- Wikipedia - Hamming Distance
Published 2026-10-02, graduate level, references Cover & Thomas 2006, Hamming 1950, and Reed-Solomon 1960.
Commenti
Caricamento commenti...
Sign in to comment