About the Hamming Code
A Hamming code is a linear error-correcting code that adds carefully placed redundant parity bits to a block of data bits. The result — the codeword — can survive a single bit being flipped (by noise, a storage fault, or a transmission glitch) and still be read correctly, because the pattern of parity checks pinpoints exactly which bit changed. Hamming codes are the basis of ECC (error-correcting code) memory, and a simple teaching example for the broader field of coding theory. This calculator encodes your data bits, optionally flips one bit to simulate an error, and then decodes and corrects it using the standard syndrome method.
The formulas
For m data bits, the calculator finds the smallest number of parity bits r that satisfies:
- 2r ≥ m + r + 1 — this guarantees enough distinct non-zero syndrome values to point at every one of the m + r bit positions (plus the all-zero "no error" case).
- Codeword length: n = m + r — the parity bits are inserted at positions that are powers of two (1, 2, 4, 8, ...); the data bits fill every remaining position, left to right.
- Each parity bit is set using even parity: it equals the XOR of every bit (in its group) whose position, written in binary, has that power-of-two bit set. For example, the parity bit at position 1 covers positions 1, 3, 5, 7, 9, ...; the one at position 2 covers 2, 3, 6, 7, 10, 11, ...
- Syndrome (decoding): XOR together the position numbers of every bit in the received codeword that equals 1. A valid codeword always produces a syndrome of 0. If exactly one bit was flipped, the syndrome equals that bit's position exactly — flip it back and the codeword, and the original data bits, are recovered.
How to get the best results
- Enter data bits as a plain string of 0s and 1s only, such as 1011 — no spaces or other characters.
- Leave Bit position to flip at 0 first to see the clean, error-free codeword and confirm the syndrome comes out to 0.
- Then set it to any position from 1 to n (shown in the "Code parameters" result) to simulate a transmission error and watch the calculator find and fix it.
- The classic textbook example is 4 data bits, which always produces the well-known Hamming(7,4) code — 3 parity bits and a 7-bit codeword.
Practical context
Real hardware and protocols use this same mechanism at much larger scale — ECC RAM, satellite and deep-space links, and some flash storage controllers all rely on Hamming-family codes to correct occasional single-bit flips without retransmitting data. A plain Hamming code corrects exactly one bit error per codeword; it cannot reliably fix (and can even miscorrect) two simultaneous errors. Systems that need to catch a second error typically add one more overall parity bit — an "extended" Hamming code, often called SECDED (single error correction, double error detection).