Beginner Basics

How to Fix a Corrupted Bit Without Knowing Exactly Which Bit Is Damaged

Hamming Code uses parity checks to find and fix one corrupted bit; two errors can mislead it, so extra parity detects double-bit corruption.

How to Fix a Corrupted Bit Without Knowing Exactly Which Bit Is Damaged

Key Takeaways

  • Hamming code uses overlapping parity bits to locate and fix a single corrupted bit; the failed checks combine into a syndrome that points to the error position.
  • It can fail with two bit errors because the code assumes at most one error, so it may report “corrected” while actually corrupting a valid bit.
  • SECDED adds an overall parity bit: it still corrects one error, but detects two-bit corruption instead of silently miscorrecting it.
  • The method came from Richard Hamming’s practical need to stop computers from abandoning jobs after detecting errors, and it remains central to ECC memory reliability.
  • Key caution: “corrected” does not always mean “correct”; the code’s guarantee depends on its assumption about how many errors occur.

Meta description: This guide explains how the Hamming Code finds and fixes one corrupted bit, why it can fail on two errors, and how SECDED detects double-bit corruption.

How to Fix a Corrupted Bit Without Knowing Exactly Which Bit Is Damaged

Tags: Hamming Code, error correction, SECDED, memory reliability

Featured image: Abstract, friendly illustration showing seven binary bits in a row, one bit highlighted and repaired by overlapping parity checks.

For anyone learning how computers protect stored data, the Hamming Code shows how a machine can find and fix one corrupted bit without being told which one it is. By adding three bits for every four data bits, it can locate and repair the wrong bit when only one bit is wrong. The idea dates to 1950, when Richard Hamming published the scheme in the Bell System Technical Journal after dealing with a Bell Labs relay computer that abandoned jobs at night.

How one flipped bit is located

Everything a computer stores is numbers in binary, and sometimes a bit changes by itself: a 0 becomes a 1 inside a memory chip or along a transmission path. The simplest defense is a parity bit, a bit added so that the total number of ones in the word is always even. If the word arrives with an odd count, something changed. That tells the receiver that there is an error, but not where it is.

Richard Hamming used several parity bits instead of one, each watching a different overlapping group of positions. In the Hamming Code tool, entering the four-bit data word 1011 adds three parity bits and returns 0110011: seven bits where there used to be four. Positions 1, 2 and 4 are the added parity bits; the remaining positions hold the data.

How to Fix a Corrupted Bit Without Knowing Exactly Which Bit Is Damaged

The tool's coverage table shows the groups. P1 watches positions 1, 3, 5 and 7. P2 watches positions 2, 3, 6 and 7. P4 watches positions 4, 5, 6 and 7. If the fifth bit is wrong, the two parity checks that cover it, P1 and P4, fail, while P2 does not. Adding the numbers of the failing checks gives 1 + 4 = 5, the position of the error. The tool writes this as syndrome 5 = 101₂, because each binary digit records whether P4, P2 and P1 reported a problem. The name syndrome, like in medicine, refers to a set of symptoms pointing to the source.

When only one bit is wrong, this is enough to correct it. In the tool, simulating an error at the fifth bit, labeled p5, returns "Corrected - error at position 5" even though no one specified which bit was wrong.

Why two errors break the trick

The same overlapping checks can point to the wrong place if two bits change. In the tool, corrupting the fifth and second bits makes all three parity groups complain: bit 5 causes P1 and P4 to fail, while bit 2 causes P2 to fail. The sum is 1 + 2 + 4 = 7. Because the code assumes at most one error, it reports "Corrected - error at position 7" and flips a bit that was already correct. The four data bits that come out are no longer 1011 but 1110. The tool adds a warning box to explain what happened; a real decoder would not show it.

SECDED, or Single Error Correction, Double Error Detection, adds one more bit, P0, in front of the others to watch the parity of the whole word. That is why the protected word has eight bits instead of seven. With one error, the group checks and the total parity agree, so the bit can be corrected. With two errors, the groups still report a problem, but the total parity adds up. That combination is only possible when an even number of bits has changed, so the decoder does not try to fix the word; it reports "Double error detected".

Why Hamming built the code

The method came from a practical annoyance. In the late 1940s, Hamming used a relay computer at Bell Labs that, when it detected an error and no operators were around, abandoned the job and moved to the next one. Nights and weekends were exactly when Hamming worked, so every error forced him to restart his programs. A taped interview cited by the Hamming code entry on Wikipedia records his question: "Damn it, if the machine can detect an error, why can't it locate the position of the error and correct it?" He published the answer in 1950.

How to Fix a Corrupted Bit Without Knowing Exactly Which Bit Is Damaged

The source of bit flips is physical. Synopsys, which designs memory controllers, explains that a bit in memory can change because of electrical noise or alpha particles, and a message traveling over a cable or through the air can also arrive with a changed bit. The correction is not a theoretical curiosity: DDR4 memory modules with ECC, or error-correcting code, in servers use a SECDED scheme with 8 check bits for every 64 data bits, according to Synopsys.

What to watch when trying it

The apparent waste is one of the first things to question. In the four-bit example, 3 of 7 bits carry no data, but the cost drops quickly as the block grows. What the added bits buy is the ability to fix an error without asking for the message again.

The more dangerous mistake is reading "Corrected" as "correct". The Hamming Code guarantees its result only under its assumption: at most one error per word. Beyond that, it does not stop or warn; it returns a wrong answer with the same confidence as a good one. That behavior is worth recognizing early because any system that always gives an answer behaves the same way, AI models included.

The Hamming Code tool's Encode tab lets a reader type any 11 data bits and see how many parity bits are added and what data rate comes out. Before trying 26 bits, it is useful to guess how many parity bits the code will need and then check the answer. In the Simulator, sending data 2000 times over a channel where each bit has a 2% chance of getting corrupted shows the difference between running with SECDED off and running with it on. The Silent failure line is the key detail. Raising the per-bit corruption probability to 10% makes silent failures grow much faster than the probability for any single bit. The simulator's numbers are random, so they change a little on each run; the point is how they move when the settings change.

Where this lesson appears

The original lesson, titled "A Corrupted Bit: How to Fix It Without Knowing Which One It Is," is part 0.3 of an AI course. It was originally published at jarroba.com on November 11, 2026, and also published in Towards AI on Medium. It follows part 2, which treats an image as a table of numbers, and leads to part 4, which asks what a model is and why a straight line already counts as one.

Comments (0)

  1. No comments yet. Be the first to share what worked for you.

Leave a comment

Comments are reviewed before they appear. Your email address is not published.