Computer Science
Advanced

Hamming Code Bits

Parity bits r needed to protect m data bits.

Formula

2r≥m+r+12^r \geq m + r + 1

Variables

mData bits
rParity bits

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

Reviewed & maintained by the FormulaWon editorial teamLast reviewed September 2026