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
- Choose Hamming(7,4) for 4 data bits or (12,8) for a byte.
- Choose Encode to add parity bits, or Decode to check and correct a received codeword.
- Enter the data bits or the codeword, most significant bit first.
- Read the codeword or corrected data, the parity bits and the syndrome; a non-zero syndrome is the position of the bit that was flipped.
Worked Example
Encode the data 1011 with Hamming(7,4). The data fills positions 3, 5, 6 and 7, and parity bits go at 1, 2 and 4: P1 = d1 ⊕ d2 ⊕ d4 = 1 ⊕ 0 ⊕ 1 = 0, P2 = d1 ⊕ d3 ⊕ d4 = 1 ⊕ 1 ⊕ 1 = 1, P4 = d2 ⊕ d3 ⊕ d4 = 0 ⊕ 1 ⊕ 1 = 0. The codeword is 0110011.
A bit flips in transit: 0110111 arrives. The checks fail for positions covered by P1 and P4 but not P2, so the syndrome is 101 = 5; flipping bit 5 back restores 0110011 and the data 1011.
The common mistake: trusting a correction when two bits went wrong. Two errors produce a syndrome pointing at a third, innocent bit, and the decoder silently makes things worse. Where double errors are possible, add an overall parity bit (SEC-DED).
Show Work
Formulas: 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. Frustrated that the machines detected errors and stopped, wasting weekend runs, he asked why they could not find and correct the error themselves, and 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.
Today ECC memory uses SEC-DED codes from the Hamming family, extended with an overall parity bit; flash storage moved on to stronger BCH and LDPC codes; and CDs, DVDs and deep-space links rely on Reed-Solomon and convolutional or turbo codes. Hamming's ideas of code distance and syndromes underlie all of them.
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 codewords carrying 4 data bits and 3 parity bits, 57% efficient. Any two codewords differ in at least three bits, so any single-bit error can be corrected.
Can it detect double errors too?
Not while correcting. With minimum distance 3 a decoder can either correct single errors or detect up to two, not both: a 2-bit error looks like a different single error and is "corrected" to the wrong word. Adding one overall parity bit (SEC-DED) fixes that.
How does the syndrome find the error?
Parity bits sit at positions 1, 2, 4 and 8, and each checks the positions whose binary number contains that bit. Recomputing the checks gives a binary number, the syndrome, equal to the position of a single flipped bit.
Hamming code or CRC?
Hamming codes correct single-bit errors in small words, as in memory. CRCs only detect errors, but they catch bursts and much more over long messages, so links use a CRC and retransmit.
What do modern systems use?
ECC memory uses SEC-DED codes in the Hamming family; flash and storage use stronger BCH and LDPC codes; CDs, DVDs and QR codes use Reed-Solomon codes, which work on multi-bit symbols.
How do I use the Hamming Code Calculator?
Simply type your numbers and read the result, which refreshes the instant you change something. There is nothing to submit and nothing to wait for.
Is it free? Does it work without internet?
Yes to both. It is free with no sign-up, and once the page has loaded it keeps working even with no internet.
Where does my data go?
Nowhere — every calculation runs on your own device. Nothing you enter is uploaded, logged, or stored.
Common Use Cases
ECC Memory
Server memory adds 8 check bits to every 64 data bits, a SEC-DED code that corrects any single-bit error and detects double errors.
Microcontroller Flash and RAM
Many safety-oriented microcontrollers protect their memories with Hamming-type ECC and report corrected errors.
Teaching Error Correction
The (7,4) code is small enough to work by hand, which makes it the standard first example of an error-correcting code.
Simple Radio Links
Short telemetry frames sometimes use Hamming-coded nibbles so a single bit hit can be fixed without retransmission.
Last updated: