Mathwords logoMathwords

Hamming Bound — Definition, Formula & Example

The Hamming bound is an upper limit on how many codewords an error-correcting code can contain, given its word length and the number of errors it must correct. It comes from requiring that the error-correction zones around codewords never overlap.

Let CC be a code of length nn over an alphabet of size qq with minimum Hamming distance dd, and let t=⌊(d−1)/2⌋t = \lfloor (d-1)/2 \rfloor. The Hamming balls of radius tt centered at the codewords are pairwise disjoint. Each ball contains ∑i=0t(ni)(q−1)i\sum_{i=0}^{t} \binom{n}{i}(q-1)^i words, and there are only qnq^n words in total, so ∣C∣|C| cannot exceed qnq^n divided by the ball size. A code that meets the bound with equality is called a perfect code. The bound limits the size of every code but does not guarantee that a code of that size exists.

Key Formula

∣C∣≤qn∑i=0t(ni)(q−1)i,t=⌊d−12⌋|C| \le \frac{q^n}{\displaystyle\sum_{i=0}^{t} \binom{n}{i}(q-1)^i}, \qquad t = \left\lfloor \frac{d-1}{2} \right\rfloor
Where:
  • ∣C∣|C| = number of codewords in the code
  • qq = alphabet size (q = 2 for binary codes)
  • nn = length of each codeword
  • dd = minimum Hamming distance between any two distinct codewords
  • tt = number of errors the code can always correct
  • (ni)(q−1)i\binom{n}{i}(q-1)^i = number of words at distance exactly i from a fixed codeword

Worked Example

Problem: A binary code has codewords of length 7, and any two codewords differ in at least 3 positions. Use the Hamming bound to find an upper bound on the number of codewords.
Step 1: Find how many errors the code can correct. With d=3d = 3:
t=⌊3−12⌋=1t = \left\lfloor \frac{3-1}{2} \right\rfloor = 1
Step 2: Count the words in a Hamming ball of radius 1 around a codeword. For q=2q = 2, the factor (q−1)i(q-1)^i equals 1. The ball holds the codeword itself plus the 7 words that differ from it in one position.
(70)+(71)=1+7=8\binom{7}{0} + \binom{7}{1} = 1 + 7 = 8
Step 3: There are 272^7 binary words of length 7. Since the balls cannot overlap, divide the total by the ball size.
∣C∣≤278=1288=16|C| \le \frac{2^7}{8} = \frac{128}{8} = 16
Answer: The Hamming bound gives ∣C∣≤16|C| \le 16. This bound happens to be achieved: the [7,4][7,4] Hamming code has exactly 16 codewords, so it is a perfect code, and 16 is the largest possible size for these parameters.

Why It Matters

In a coding theory course, the Hamming bound is the first test you apply to a proposed code: if the parameters violate it, no such code exists. It also defines perfect codes, such as the Hamming codes and the binary Golay code of length 23. These codes waste no space, which is why Hamming codes are used in ECC computer memory.

Common Mistakes

Mistake: Using the minimum distance dd as the ball radius instead of t=⌊(d−1)/2⌋t = \lfloor (d-1)/2 \rfloor.
Correction: The disjoint balls have radius tt, the number of correctable errors. With d=3d = 3, use radius 1, not 3. Using dd makes the balls too large and gives a bound that is not valid.

Related Terms

  • Sphere Packing — Packing idea behind non-overlapping correction zones
  • Coding Theory — The field where this bound limits error-correcting codes
  • Upper Bound — Hamming bound is an upper bound on code size