② Encoded codeword (click any bit to flip — simulate an error)
✓ No errors detected
③ Corrected / received message bits
Parity-check matrix H (rows = parity checks)
Syndrome s = H · r̃ (received codeword)
s = 000 → no error
About Hamming Error-Correcting Codes
Hamming codes, invented by Richard Hamming at Bell Labs in 1950, are the simplest class of linear error-correcting codes. By inserting redundant parity bits at power-of-2 positions within a data word, they create a codeword where any single-bit corruption can be located and reversed without retransmitting the data.
The key insight is the parity-check matrix H: each column is the binary representation of its position index, so the syndrome s = H·r computed from the received codeword r directly spells out the erroneous bit's position in binary. Flip that bit and the original message is recovered. SECDED extends this by one overall parity bit, raising the minimum Hamming distance to 4 — enough to detect two simultaneous errors even if it can only correct one.
This simulation lets you explore Hamming(7,4) and SECDED(8,4) interactively. Toggle the four message bits, then click any bit in the encoded codeword to inject a single-bit error (or two bits to test double-error detection). Watch the syndrome highlight which bit position is faulty and see the corrected message appear instantly.
Frequently Asked Questions
What is a Hamming code?
A Hamming code is a linear error-correcting code invented by Richard Hamming in 1950. It adds redundant parity bits to a data word so that any single-bit error can be detected and corrected. Hamming(7,4) encodes 4 data bits into a 7-bit codeword using 3 parity bits placed at power-of-2 positions.
How does syndrome decoding work?
After receiving a codeword, the decoder multiplies it by the parity-check matrix H to produce a syndrome vector s = H·r mod 2. If s = 0 there are no errors. If s is non-zero, its binary value directly gives the position of the erroneous bit, which is then flipped to correct the error.
What is SECDED and why does it matter?
SECDED stands for Single Error Correct, Double Error Detect. It extends Hamming(7,4) to Hamming(8,4) by adding an overall parity bit. The extra bit increases the minimum Hamming distance from 3 to 4, allowing the code to correct any single-bit error while also detecting (but not correcting) any double-bit error. ECC RAM in servers uses SECDED to protect against bit flips caused by cosmic rays or voltage fluctuations.
Where are Hamming codes used in practice?
Hamming codes are used in ECC RAM found in servers and workstations, in satellite communication links, in DRAM memory controllers, in some NAND flash memory systems, and historically in telecommunications. They are the conceptual foundation for more advanced codes like Reed-Solomon and turbo codes.
Why are parity bits placed at power-of-2 positions?
Positions 1, 2, 4, 8, … (powers of 2) are chosen so that each parity bit covers a unique subset of data positions defined by the corresponding bit of the binary position number. This ensures that the syndrome of any single-bit error directly encodes the error position in binary, making correction straightforward without a lookup table.
What is the Hamming distance?
The Hamming distance between two binary strings is the number of positions where they differ. The minimum Hamming distance d_min of a code determines its error-correcting power: a code can correct up to floor((d_min-1)/2) errors and detect up to d_min-1 errors. Hamming(7,4) has d_min = 3, so it corrects 1 error; SECDED has d_min = 4, correcting 1 and detecting 2.
What is the code rate of Hamming(7,4)?
The code rate is the ratio of data bits to total codeword bits. For Hamming(7,4) the rate is 4/7 ≈ 0.571, meaning about 57% of the transmitted bits carry information and 43% are redundancy. As the block size grows, Hamming codes become more efficient: Hamming(15,11) has rate 11/15 ≈ 0.733.
Can Hamming codes correct more than one bit error?
Standard Hamming(7,4) can only correct single-bit errors. If two bits are flipped, the syndrome points to a wrong position and the decoder makes things worse rather than better. SECDED can detect (but not correct) double-bit errors. For correcting multiple errors, stronger codes like Reed-Solomon, LDPC, or turbo codes are used.
How is the parity-check matrix H constructed?
For Hamming(7,4), each column of H is the binary representation of the column's position (1 to 7). Column 1 = 001, column 2 = 010, column 3 = 011, and so on. Rows correspond to parity checks s1, s2, s4. The syndrome s = H·r isolates the error position because each bit position has a unique binary encoding as a column of H.
What is the difference between error detection and error correction?
Error detection means the receiver can tell that something went wrong (and may request a retransmission), but cannot fix it. Error correction means the receiver has enough redundancy to reconstruct the original data without retransmission. Hamming codes provide both: they detect up to 2 errors and correct 1, making them ideal for channels where retransmission is impractical, such as deep-space communication or RAM.
About Hamming Codes SECDED
Hamming codes are a family of linear error-correcting codes invented by Richard Hamming at Bell Labs in 1950. A Hamming(7,4) code encodes 4 data bits into 7 codeword bits by adding 3 parity bits placed at power-of-two positions (1, 2, 4); each parity bit covers a specific subset of data bit positions defined by the columns of the parity-check matrix H. This arrangement gives the code a minimum Hamming distance of 3, guaranteeing it can correct any single-bit error and detect any two-bit error. Adding one overall parity bit produces the SECDED (Single-Error Correcting, Double-Error Detecting) Hamming(8,4) code used in ECC RAM, where a flipped memory bit is automatically corrected each time the memory is read.
The simulator lets you enter 4-bit data words, watch the parity-check matrix encode them into 7- or 8-bit codewords, inject single or double bit flips, and observe syndrome decoding: the syndrome vector s = H·r (mod 2) directly points to the position of the erroneous bit, allowing automatic correction in one step.
Frequently Asked Questions
How does syndrome decoding locate a single-bit error?
After receiving a codeword r, the decoder computes the syndrome s = H·r (mod 2), where H is the parity-check matrix. If s = 0, no error is detected. If s ≠ 0, it equals one of the columns of H; the position of that column identifies the bit to flip. For Hamming(7,4), the syndrome is a 3-bit binary number directly equal to the 1-based index of the erroneous bit, making correction trivially fast in hardware.
What is the Hamming distance and why is it important?
The Hamming distance between two codewords is the number of bit positions in which they differ. A code with minimum Hamming distance d_min can detect up to d_min − 1 errors and correct up to ⌊(d_min − 1)/2⌋ errors. Hamming(7,4) has d_min = 3, so it corrects 1 error and detects 2. To correct t errors you need d_min ≥ 2t + 1; the minimum codeword length for this grows as O(t log n) by the Hamming bound (sphere-packing bound).
What is ECC RAM and how does it use Hamming codes?
Error-Correcting Code RAM uses a Hamming SECDED scheme on each 64-bit memory word, adding 8 check bits (72 bits stored per word). Each time a word is read, the syndrome is computed in hardware; a single-bit error is corrected transparently in one memory cycle (~60 ns on DDR5) with no software involvement. ECC RAM is standard in servers and workstations where silent data corruption could compromise financial, medical, or scientific computations.
Why are parity bits placed at power-of-two positions?
In Hamming's construction, parity bit at position 2ᵏ covers all bit positions whose binary representation has a 1 in the kth bit. For example, parity bit 1 (position 001₂) covers positions 1, 3, 5, 7 (all positions with bit 0 set). This ensures each data position is covered by a unique non-empty subset of parity bits, so the syndrome uniquely identifies any single-error position. The power-of-two placement makes this subset structure elegant and efficient.
What is the difference between Hamming(7,4) and Hamming(8,4) SECDED?
Hamming(7,4) uses 3 parity bits over 4 data bits and corrects 1 error (d_min = 3). Adding a fourth overall parity bit (XOR of all 7 bits) creates Hamming(8,4), which detects double errors by noticing when the syndrome is non-zero but the overall parity checks out, signalling a 2-bit error pattern. This SECDED property is crucial for memory systems where two errors are rare but possible during cosmic-ray events or multi-cell upsets.
What are Reed-Solomon codes and how do they compare?
Reed-Solomon codes operate over larger alphabets (symbols of k bits rather than single bits) and can correct multiple symbol errors. A Reed-Solomon(255,223) code (used in CDs, DVDs, QR codes, and deep-space communications) corrects up to 16 symbol errors per 255-symbol block. While Hamming codes are optimal for correcting single-bit errors with minimum redundancy, Reed-Solomon is far more powerful for burst errors and is preferred in storage and satellite communication.
What is the Hamming bound (sphere-packing bound)?
The Hamming bound states that for a binary code of length n correcting t errors, the number of codewords M satisfies M · Σᵢ₌₀ᵗ C(n,i) ≤ 2ⁿ. Codes achieving equality are called perfect codes; Hamming codes are perfect (their error spheres of radius 1 partition the entire n-bit space with no gaps). The only other binary perfect codes are the trivial repetition code and the Golay(23,12) code.
How are Hamming codes used beyond RAM?
Hamming codes appear in satellite telemetry (protecting command uplinks), NAND flash ECC (though BCH codes are more common for multi-bit correction), early data transmission modems, magnetic tape, and network protocol headers. Hamming(7,4) is also a classic teaching example in information theory and algebraic coding theory courses, illustrating the power of linear algebra over GF(2).
What happens if there are two simultaneous bit errors in Hamming(7,4)?
With only single-error correction (no overall parity bit), a 2-bit error produces a non-zero syndrome that matches some column of H — but the wrong one. The decoder "corrects" the wrong bit, introducing a third error and corrupting the data silently. SECDED (8,4) prevents this: the overall parity bit distinguishes 1-bit errors (odd parity mismatch + non-zero syndrome) from 2-bit errors (even parity mismatch + non-zero syndrome), flagging the latter rather than miscorrecting.