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 · 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.

  1. Encode: type your data bits. The codeword appears with parity bits outlined, plus a table of what each parity bit checks.
  2. Test: tap any bit of the codeword to flip it. The check result shows the syndrome and the bit it corrects.
  3. 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 bits for data 1011
Parity bitChecks positionsData bits thereValue
p11, 3, 5, 71 0 10
p22, 3, 6, 71 1 11
p44, 5, 6, 70 1 10

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.

Parity bits needed by data length
Data bitsParity bitsCodeExtendedOverheadTry it
43(7,4)(8,4)42.9%Encode 4 bits
84(12,8)(13,8)33.3%Encode 8 bits
114(15,11)(16,11)26.7%Encode 11 bits
165(21,16)(22,16)23.8%Encode 16 bits
265(31,26)(32,26)16.1%Encode 26 bits
326(38,32)(39,32)15.8%Encode 32 bits
576(63,57)(64,57)9.5%Encode 57 bits
647(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.

Single and double bit errors over all messages
CodeMessages1-bit errors corrected2-bit errors detected2-bit errors turned into wrong data
(7,4)16112 of 1120%100%
(8,4) SECDED16128 of 128100%0%
(12,8)2563,072 of 3,07222.7%77.3%
(13,8) SECDED2563,328 of 3,328100%0%
(15,11)2,04830,720 of 30,7200%100%
(16,11) SECDED2,04832,768 of 32,768100%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.