Hamming Code Calculator
Encode 4-bit or 8-bit data with Hamming(7,4) or Hamming(12,8) single-error correcting code. Decode and correct single-bit errors automatically.
How to Use
- Pick (7,4) or (12,8) code variant.
- Enter data bits — parity bits are computed automatically at positions 1, 2, 4, 8.
- Decode any received codeword to detect and correct single-bit errors.
Show Work
How Hamming Works
History of the Hamming Code
Richard Hamming worked at Bell Labs in the late 1940s using early mechanical computers with punch-card input. Tired of the machines stopping on weekend jobs due to single-bit errors ("I found myself asking, \'If the machine can detect the error, why can\'t it correct it?\'"), he developed the first practical single-error-correcting code in 1947 and published it in 1950 as "Error detecting and error correcting codes" in the Bell System Technical Journal.
The Hamming code\'s elegance is in the parity-bit placement: putting parity bits at power-of-2 positions (1, 2, 4, 8, ...) means each data bit contributes to a unique combination of parity checks, and the resulting syndrome — XOR of the parity checks at the receiver — directly identifies the position of any single-bit error. The mathematics generalize to Hamming(2m−1, 2m−m−1) codes for any m, with the familiar (7,4) as m=3.
Modern applications: every ECC RAM DIMM uses SEC-DED Hamming (extended with an overall parity bit); NAND flash memory uses Hamming or more powerful BCH codes for per-page ECC; deep-space communication (Voyager, New Horizons) uses concatenated codes with Hamming as the inner code; and CD-ROM/DVD use Reed-Solomon (a generalization of Hamming to multi-bit symbols) for audio/video reliability.
About This Calculator
Pick Hamming(7,4) or Hamming(12,8), select encode or decode mode, and enter your bit string. In encode mode, the tool places parity bits at the correct power-of-2 positions and fills them with the XOR of the data bits each covers. In decode mode, it computes the syndrome, identifies any single-bit error position, and reports the corrected data.
(7,4) is the original textbook Hamming code; (12,8) is a useful 8-data-bit variant for aligning with byte-sized storage. Neither detects 2-bit errors reliably — for that, add an overall parity bit (SEC-DED) or use Reed-Solomon / BCH codes. Everything runs client-side; no values leave your browser.
Frequently Asked Questions
What does Hamming(7,4) mean?
Seven-bit codeword with 4 data bits and 3 parity bits. Can detect up to 2 bit errors and correct single-bit errors. Ratio 4/7 ≈ 57% efficient.
How does it work?
Parity bits are placed at power-of-2 positions (1, 2, 4, 8). Each parity bit covers a specific subset of data bits. On decode, XOR the received bits by their parity masks to get a 'syndrome' — nonzero syndrome points to the erroneous bit.
Hamming vs CRC?
Hamming corrects single-bit errors but is limited in error detection. CRC detects burst errors but doesn't correct. Use Hamming for memory (ECC RAM); CRC for communication and storage checksums.
Common Use Cases
ECC RAM
Server-grade memory uses SEC-DED (single-error correct, double-error detect) derived from Hamming.
NAND Flash
Most solid-state storage uses Hamming or BCH codes for per-page error correction.
Deep-Space Communication
Concatenated codes starting with Hamming are used by interplanetary probes for weak-signal recovery.
Last updated: