Hamming Code Calculator
Enter data bits to get the codeword, or paste a received codeword to find and fix a flipped bit. Data 1011 encodes to 0110011 in Hamming(7,4).
By Hommer Zhao · Updated
How to use the Hamming code calculator
A Hamming code adds parity bits to data so that any single flipped bit can be located and corrected.
- Encode: type your data bits. The codeword appears with parity bits outlined, plus a table of what each parity bit checks.
- Test: tap any bit of the codeword to flip it. The check result shows the syndrome and the bit it corrects.
- Check & correct: paste a received codeword. Its length sets the code size; you get the failed checks, the corrected codeword and the data bits.
How to calculate a Hamming code: 1011 → 0110011
Number the positions from 1. Parity bits go at 1, 2 and 4; the data bits 1, 0, 1, 1 fill positions 3, 5, 6 and 7. Each parity bit makes the count of 1s even across the positions it checks:
| Parity bit | Checks positions | Data bits there | Value |
|---|---|---|---|
| p1 | 1, 3, 5, 7 | 1 0 1 | 0 |
| p2 | 2, 3, 6, 7 | 1 1 1 | 1 |
| p4 | 4, 5, 6, 7 | 0 1 1 | 0 |
So the codeword is p1 p2 d1 p4 d2 d3 d4 = 0110011. Open this example in the calculator.
To correct it, recompute the checks on the received word. If bit 5 flips, 0110111 arrives: checks p1 and p4 fail, p2 passes, so the syndrome is 101 in binary (p4 p2 p1) = 5. Flip position 5 back to get 0110011 and data 1011. Check this word in the calculator.
How many parity bits? Hamming code sizes
For m data bits you need the smallest r with 2r ≥ m + r + 1. Extended Hamming adds one more bit for double-error detection.
| Data bits | Parity bits | Code | Extended | Overhead | Try it |
|---|---|---|---|---|---|
| 4 | 3 | (7,4) | (8,4) | 42.9% | Encode 4 bits |
| 8 | 4 | (12,8) | (13,8) | 33.3% | Encode 8 bits |
| 11 | 4 | (15,11) | (16,11) | 26.7% | Encode 11 bits |
| 16 | 5 | (21,16) | (22,16) | 23.8% | Encode 16 bits |
| 26 | 5 | (31,26) | (32,26) | 16.1% | Encode 26 bits |
| 32 | 6 | (38,32) | (39,32) | 15.8% | Encode 32 bits |
| 57 | 6 | (63,57) | (64,57) | 9.5% | Encode 57 bits |
| 64 | 7 | (71,64) | (72,64) | 9.9% | Encode 64 bits |
Overhead = parity bits ÷ codeword bits, without the extended bit. Lengths that are not 2r − 1, such as (12,8), are shortened codes: the calculator drops the unused high positions.
What happens with two flipped bits? Exhaustive test
We encoded every possible message, then flipped every single bit and every pair of bits, and decoded each result with the calculator's code.
| Code | Messages | 1-bit errors corrected | 2-bit errors detected | 2-bit errors turned into wrong data |
|---|---|---|---|---|
| (7,4) | 16 | 112 of 112 | 0% | 100% |
| (8,4) SECDED | 16 | 128 of 128 | 100% | 0% |
| (12,8) | 256 | 3,072 of 3,072 | 22.7% | 77.3% |
| (13,8) SECDED | 256 | 3,328 of 3,328 | 100% | 0% |
| (15,11) | 2,048 | 30,720 of 30,720 | 0% | 100% |
| (16,11) SECDED | 2,048 | 32,768 of 32,768 | 100% | 0% |
A full-length plain Hamming code such as (7,4) or (15,11) always "corrects" a two-bit error into wrong data. The shortened (12,8) code catches some pairs only because their syndrome points past position 12. The extended versions flagged every two-bit error in this test. Try extended mode and flip two bits.
Hamming code FAQ
What is a Hamming code?
An error-correcting code that inserts parity bits at positions 1, 2, 4, 8 and so on. Each parity bit checks a different set of positions, so the pattern of failed checks points to the one bit that flipped.
How many errors can a Hamming code correct?
One bit per codeword. A plain Hamming code cannot tell a two-bit error from a one-bit error, so it miscorrects it. Extended Hamming (SECDED) corrects one bit and detects, but cannot fix, two.
What is Hamming(7,4)?
A code that sends 7 bits for every 4 data bits: parity bits at positions 1, 2 and 4, data at 3, 5, 6 and 7. Data 1011 becomes 0110011.
How do I find the error position from the syndrome?
Recompute each parity check on the received word. Write a 1 for every failed check, with p1 as the lowest bit. That binary number is the position of the flipped bit. A syndrome of 0 means every check passed; in extended mode, a failed overall parity bit with syndrome 0 means only that last bit flipped.
Even or odd parity: which should I use?
Use the one your course or system specifies; this calculator defaults to even. Even parity makes each checked group contain an even number of 1s, odd parity an odd number. Both locate and correct errors the same way, as long as sender and receiver agree.
Is a Hamming code the same as Hamming distance?
No. Hamming distance counts the positions where two equal-length strings differ. A Hamming code is an error-correcting code whose codewords are at least distance 3 apart, which is what lets it fix one bit.
Need more than one corrected bit per block? Try the BCH code encoder and decoder. To compare two bit strings, use the Hamming distance calculator.