What Is a Hamming Code?
A Hamming code is a linear error-correcting code that adds parity bits to binary data so a receiver can not only detect but also correct a single-bit error automatically. Invented by Richard Hamming in 1950, it is a leap beyond a plain parity bit, which can only detect errors. The trick: parity bits are placed at power-of-two positions (1, 2, 4, 8…) and each checks a specific overlapping group of bits, so the pattern of failing checks — the syndrome — points straight to the position of any flipped bit. This calculator encodes data into a Hamming codeword and decodes received words to locate and fix errors, showing every parity group and the syndrome.
How to Use This Calculator
Encode mode: enter your data bits and the calculator builds the full codeword, marking parity positions in blue and data positions in green, with a coverage row for each parity bit. Decode & Correct mode: paste a received codeword; the calculator recomputes every parity check, forms the syndrome, and if a single bit flipped it highlights that position in red and reports the corrected codeword and extracted data. Choose even or odd parity convention to match your system.
How Many Parity Bits Do You Need?
For m data bits you need the smallest number of parity bits r that satisfies 2r ≥ m + r + 1. The parity bits plus data bits form an n = m + r bit codeword, written Hamming(n, m).
| Data bits (m) | Parity bits (r) | Codeword (n) | Name |
|---|---|---|---|
| 1 | 2 | 3 | Hamming(3,1) |
| 4 | 3 | 7 | Hamming(7,4) |
| 8 | 4 | 12 | Hamming(12,8) |
| 11 | 4 | 15 | Hamming(15,11) |
| 26 | 5 | 31 | Hamming(31,26) |
How to Encode with Hamming(7,4) — Worked Example
Encoding data 1011
Positions 1, 2, 4 hold parity bits; positions 3, 5, 6, 7 hold the data 1, 0, 1, 1. Each parity bit is set for even parity over its group: P1 covers positions 1,3,5,7; P2 covers 2,3,6,7; P4 covers 4,5,6,7. The result is the codeword 0110011.
How the Syndrome Corrects Errors
At the receiver, every parity check is recomputed. Each check contributes one bit to the syndrome: 0 if it passes, 1 if it fails. Read as a binary number, the syndrome is either 0 (no error) or the exact position of the flipped bit. For example, if the codeword 0110011 arrives as 0110111 (bit 5 flipped), the parity checks fail in a pattern that spells binary 101 = 5 — so the calculator flips position 5 back and recovers the original data. This is why a Hamming code corrects any single-bit error while a lone parity bit cannot.
Hamming Code vs Parity Bit
| Feature | Single parity bit | Hamming code |
|---|---|---|
| Extra bits | 1 | r (grows with data) |
| Detects single error | yes | yes |
| Locates the error | no | yes (syndrome) |
| Corrects single error | no | yes |
Where Hamming Codes Are Used
Hamming and related codes protect data throughout computing: ECC memory (which uses SECDED, a Hamming code plus an extra parity bit for double-error detection), flash storage, satellite and deep-space links, and older modem and bus protocols. They are the classic introduction to coding theory. To build the underlying parity, use the Parity Bit Calculator; for the XOR logic behind every parity check, see the Logic Gate Calculator; and for the binary itself, the Binary Calculator and Number System Converter.
Frequently Asked Questions
What is a Hamming code?
A linear error-correcting code that adds parity bits at power-of-two positions so a receiver can detect and correct any single-bit error using the syndrome.
How does a Hamming code correct errors?
Each parity bit covers a set of positions. The failing checks form the syndrome, a binary number that equals the position of the flipped bit; flipping that bit back corrects the error.
How many parity bits does a Hamming code need?
The smallest r with 2r ≥ m + r + 1. Four data bits need 3 parity bits (Hamming(7,4)); eight need 4; eleven need 4 (Hamming(15,11)).
What is Hamming(7,4)?
The most common Hamming code: 4 data bits encoded into a 7-bit codeword with 3 parity bits, able to correct any single-bit error.
What is a syndrome in a Hamming code?
The binary number formed by the recomputed parity checks. Zero means no error; a non-zero value is the exact position of the single flipped bit.
What is the difference between a parity bit and a Hamming code?
A single parity bit only detects an odd number of errors. A Hamming code uses several parity bits whose combined checks locate and correct a single-bit error.