Hamming Code Bits
Parity bits r needed to protect m data bits.
Formula
Variables
Example
4 data bits need 3 parity bits
How it works
In a Hamming code, each parity bit can distinguish between two possibilities, so r parity bits can create up to 2^r different syndrome patterns. Those patterns must cover every possible single-bit error position in the m data bits plus the parity bits themselves, and also the "no error" case, which is why the total needed is at least m + r + 1. The inequality tells you the smallest number of parity bits that makes single-error correction possible for a block of m data bits.
When to use it
Use this when designing or analyzing simple error-correcting codes for memory, communication links, or low-level hardware storage where you want to correct one-bit errors efficiently. It is especially useful when you know the payload size and need to choose how many check bits to add before encoding.
Worked example, step by step
Suppose you want to protect m = 11 data bits.
Check r = 3: 2^3 = 8, and m + r + 1 = 11 + 3 + 1 = 15, so 8 < 15, not enough.
Check r = 4: 2^4 = 16, and m + r + 1 = 11 + 4 + 1 = 16, so 16 >= 16, enough.
Therefore, the minimum number of parity bits needed is r = 4.
So an 11-bit data block requires 4 parity bits in a Hamming code.
Common mistakes to avoid
- Forgetting to include the parity bits themselves in m + r + 1
- Using the formula for multi-bit error correction instead of single-bit error correction
- Assuming any r that satisfies the inequality is the only valid choice, instead of the minimum r that satisfies it
Did You Know?
Hamming codes can both detect and correct single-bit errors, quietly protecting memory and deep-space signals.
Share this formula
More in Computer Science
View allGustafson’s Law
IntermediateIdeal scaled-workload speedup when more processors allow a larger parallel task in the same elapsed time. Here s is the serial fraction of the parallel execution time, not the single-processor fraction used in Amdahl’s law.
Hick–Hyman Law (Equal Choices)
IntermediateModels choice reaction time for n equally likely alternatives (n ≥ 1). This information-theoretic form assumes comparable, practised stimulus–response choices; it is not a universal law of menu browsing.
Fitts’s Law (Shannon Form)
IntermediateAn empirical model of aimed movement time: farther or narrower targets generally take longer to reach. Use D ≥ 0, W > 0 and fitted coefficients for the device and task.
Shannon Entropy
AdvancedAverage information content of a random source (bits).
Master Theorem (form)
AdvancedAnalyzes running time of divide-and-conquer algorithms.
Hamming Distance
AdvancedNumber of positions at which two strings differ.