Hamming Code Calculator
Encode data bits into a Hamming code (7,4), (15,11) or any length with parity bits at positions 1, 2, 4, 8…, optionally extended SECDED — or check a received codeword, find the syndrome and correct a single-bit error.
How it works
Parity bits at positions 1, 2, 4, 8 … (powers of two); data bits fill the rest · r parity bits protect k data bits when 2ʳ ≥ k + r + 1 · parity bit p = XOR of all positions whose index has bit p set (even parity) · syndrome = XOR of the positions of all 1-bits in the received word = position of a single error · SECDED adds an overall parity bit to tell single from double errors
Richard Hamming’s code places parity bits at the power-of-two positions so that each data position is checked by a unique combination of parity bits. When one bit flips, the failed checks spell out its position in binary — the syndrome — so the receiver can flip it back. The extended (SECDED) version adds one overall parity bit: a non-zero syndrome with correct overall parity means two bits flipped, which is detected but not corrected. ECC memory uses exactly this scheme, typically (72,64).
Worked example
Encoding 1011 needs 3 parity bits (2³ ≥ 4 + 3 + 1), giving Hamming (7,4). Data goes to positions 3, 5, 6, 7; P1 = d3 ⊕ d5 ⊕ d7 = 0, P2 = d3 ⊕ d6 ⊕ d7 = 1, P4 = d5 ⊕ d6 ⊕ d7 = 0, so the codeword is 0110011 (code rate 4/7 = 57.14%). If position 5 is received flipped (0110111), the syndrome is 101 = 5 and the decoder corrects it.
Sources: R. W. Hamming, Error detecting and error correcting codes, Bell System Technical Journal 29(2), 1950 · Hamming code — Wikipedia
Frequently asked questions
How many parity bits does a Hamming code need?
The smallest r with 2ʳ ≥ k + r + 1: 3 parity bits for 4 data bits (7,4), 4 for 11 (15,11), 5 for 26 (31,26), 6 for 57 (63,57). Add one more for SECDED, e.g. (8,4) or (72,64).
How is the error position found?
XOR together the positions of all bits that are 1 (equivalently, recompute each parity check). The result, read in binary, is the syndrome: 0 means no error, any other value is the position of the flipped bit.
Can Hamming code correct two errors?
No. Plain Hamming code corrects one error; with two errors it “corrects” the wrong bit. Extended Hamming (SECDED) detects double errors so they can be reported instead of silently miscorrected, but correcting more errors needs stronger codes such as BCH or Reed–Solomon.
Does it use even or odd parity?
Even parity, the textbook convention: each parity bit makes the number of 1s in its group even. Some exercises use odd parity — then every parity bit is inverted, but the positions and syndrome logic are the same.
Related calculators
This calculator is for educational purposes. Double-check important results before acting on them.