The Daily Reckoning
How Can Seven Bits Repair One Broken Bit?
Three overlapping parity checks do more than notice a flipped bit: their pattern names the exact position to repair.
- Difficulty
- Intermediate
- Area
- Discrete mathematics and computation
- Reading time
- 9 minutes
- Prerequisites
- Binary digits · Even and odd numbers · Powers of two
A machine sends four binary digits:
During storage or transmission, one digit flips. A becomes , or a becomes . If the receiver sees only the damaged four digits, the receiver cannot know which digit changed—or even whether anything changed.
Add three carefully chosen digits before sending, however, and the seven-digit block can repair any one flipped digit by itself. The extra digits do not copy the message. They answer three overlapping yes-or-no questions whose combined answer identifies the damaged position.
Three questions can name eight outcomes
A single parity bit records whether a group contains an even or odd number of s. Under the even-parity convention, the parity bit is chosen so that the entire group contains an even number of s. If one digit in the group flips, the group’s parity changes from even to odd.
One parity check can say only “pass” or “fail.” Three checks can produce
different patterns. That is exactly enough for eight possibilities: no error, or an error in one of seven positions.
The Hamming code turns four data bits into a seven-bit codeword. Positions , , and hold parity bits. Positions , , , and hold the four data bits. The three parity checks cover these positions:
The check numbers , , and are powers of two. Write every position from through in three-digit binary form:
The binary label tells you which checks watch that position. Position has label , so checks and watch it, while check does not.
The interactive diagram below begins with the valid codeword . Select any position to flip its bit. The diagram keeps to Hamming’s promise that at most one position is damaged at a time.
Interactive error-correcting code
Flip one bit, then let three parity checks find it
All three checks pass. The codeword is clean.
The three check results form a syndrome. Read the results in the order check , check , check . A passing check contributes and a failing check contributes . The syndrome is the binary representation of , so it names position .
The rule in one matrix
Let
be the seven received bits, where is the bit in position . Addition is performed modulo , so . Equivalently, addition is the exclusive-or operation, written .
The parity-check matrix is
The first row marks the positions watched by check ; the second marks check ; the third marks check . The syndrome vector is
Here, means the received row of bits written as a column. Each column of is the three-digit binary label of its position, read from bottom to top when the syndrome is displayed as . If bit alone flips, the syndrome becomes column of . The location is built into the matrix.
Worked example: encode, damage, repair
Encode the data word . Put its digits into positions , , , and :
The symbols , , and denote the parity bits.
For check , the data bits in positions , , and are , , and . They already contain two s, so choose :
For check , the data bits in positions , , and are all . Three is odd, so choose to make the total even:
For check , positions , , and contain , , and . Two s are already even, so :
The complete codeword is therefore
Suppose position flips from to . The receiver gets
Now evaluate all three checks:
Thus
Flip position back to . The repaired codeword is , and its data positions once again read .
Try two transmissions
Problem 1
Encode the data word by placing its digits in positions , , , and . Use even parity. What seven-bit codeword do you obtain?
Reveal the solution
Start with
Check sees positions , , and , which contain three s. Set to make the total even.
Check sees data values , , and in positions , , and . Two s are even, so .
Check sees data values , , and in positions , , and . Again the total is even, so .
The codeword is
Problem 2
The codeword from Problem 1 is sent, but the receiver gets . Find the syndrome and repair the error.
Reveal the solution
Compute the three checks:
The syndrome is
Position is wrong. Flip its back to to recover .
A lost weekend becomes a new subject
Richard Hamming arrived at Bell Telephone Laboratories in 1946 after running computing machines for the Manhattan Project at Los Alamos. The wartime work did not dictate the code, but it placed Hamming among a postwar movement of mathematicians who treated reliable large-scale computation as a serious research problem.
At Bell Labs in 1947, Hamming left a calculation running over a weekend. An error stopped the machine, and he returned on Monday to find no useful result. The University of St Andrews’ biography of Hamming records the question that followed: if a machine could detect an error, why could it not locate and correct the error?
Hamming was not working in isolation. He shared Bell Labs’ mathematical research environment with Claude Shannon and John Tukey. Shannon’s 1948 paper “A Mathematical Theory of Communication” established a general theory of communication through noisy channels. Hamming attacked one constructive part of that larger problem: how a finite pattern of redundant symbols could correct mistakes efficiently.
Hamming’s “Error Detecting and Error Correcting Codes” appeared in the Bell System Technical Journal in April 1950. The paper defined the distance between two binary words as the number of positions where they differ, now called Hamming distance. Valid Hamming codewords are at least three flips apart. A received word one flip from a valid codeword therefore has one unambiguous nearest codeword.
What the guarantee does—and does not—cover
Distance three guarantees correction of any one-bit error. The same distance can instead guarantee detection of any two-bit error, because two flips cannot turn one valid codeword into another. A basic Hamming decoder cannot reliably do both jobs at once: two flipped bits can produce a syndrome that impersonates a one-bit error at a third position.
Adding one overall parity bit creates an extended Hamming code with distance four. That version supports single-error correction and double-error detection, usually abbreviated SECDED. Infineon’s documentation for static random-access memory describes how error-correcting circuitry stores parity alongside each data word and repairs a single-bit fault as the word is read.
The seven-bit code in this lesson is small enough to inspect by hand. Practical memory systems use wider codewords and hardware designed around the same ideas. Communications systems also add structured redundancy, although modern channels often use stronger descendants such as Bose–Chaudhuri–Hocquenghem, Reed–Solomon, low-density parity-check, or polar codes when many errors or long blocks must be handled.
One idea to remember
Redundancy can carry an address. Hamming’s three parity bits do more than announce that a bit changed: the pattern of failed checks is the binary number of the position to repair.
A useful next step is to derive why parity bits support a Hamming code of length , or to study Hamming distance as a geometry of binary words. For another compact binary cycle, revisit why a prime makes giant powers loop.
Sources
- Richard W. Hamming, “Error Detecting and Error Correcting Codes”, Bell System Technical Journal 29, no. 2 (April 1950), 147–160.
- Claude E. Shannon, “A Mathematical Theory of Communication”, Bell System Technical Journal 27 (July and October 1948), 379–423 and 623–656.
- J. J. O’Connor and E. F. Robertson, “Richard Wesley Hamming”, MacTutor History of Mathematics, University of St Andrews, updated January 2012.
- Infineon Technologies, “Error Correcting Code to Detect and Correct Single-Bit Errors”, updated April 21, 2025, on Hamming-code circuitry in static random-access memory.