Experience how a Hamming(7,4) code does more than detect an error — it pinpoints which bit went wrong and fixes it automatically. Build a codeword from four data bits, inject a single-bit error anywhere, and watch the syndrome point at the error position as it is corrected in real time.
Parameters
Data bit 1
Goes into codeword position 3 (0 or 1)
Data bit 2
Goes into codeword position 5 (0 or 1)
Data bit 3
Goes into codeword position 6 (0 or 1)
Data bit 4
Goes into codeword position 7 (0 or 1)
Error injection position
0 = no error, 1–7 = flip the bit at that position
Results
—
Codeword (7 bits)
—
Parity bits p1·p2·p4
—
Syndrome
—
Detected error position
—
Corrected data
—
Correction outcome
—
Codeword & syndrome — error-detection animation
The 7-bit codeword is shown as cells at positions 1–7. Parity bits (positions 1·2·4) and data bits are coloured differently; the injected error cell pulses red. The three arcs below show each parity bit's coverage, and the arrow marks the error position pointed to by the syndrome.
Encoding (even parity). Parity bits sit at the power-of-two positions 1, 2, 4, and data bits d1–d4 occupy positions 3, 5, 6, 7. The symbol $\oplus$ denotes exclusive OR (XOR).
Decoding. The three syndrome bits are computed from the received word r (positions r1–r7).
$$\text{syndrome}=4\,s_4+2\,s_2+s_1$$
The syndrome (s4 s2 s1), read as a binary number, is exactly the position of the erroneous bit (0 means no error). Flipping that bit completes the correction.
What is the Hamming Code Simulator?
🙋
I learned that a "parity bit" checks data for errors when it is transmitted. But this tool says it "corrects" errors. Aren't checking and correcting the same thing?
🎓
That is exactly today's key point. An ordinary parity bit is just one bit. It only looks at whether the number of ones is even or odd, so it can tell that an error happened but not which of the seven bits is wrong. There is no way to fix it. A Hamming code uses three parity bits — and each of the three deliberately watches a different, overlapping set of bits. When an error occurs, the pattern of which checks fail tells you the address of the wrong bit in binary.
🙋
Tells you the address...? How does having three parity bits reveal the position?
🎓
Roughly: line up the fail/pass of the three parity bits as 0/1 and you get a three-digit binary number, which can represent 0 to 7. Hamming's stroke of genius was to assign coverage so that the parity at position 1 handles the 1s-place of the address, position 2 the 2s-place, and position 4 the 4s-place. So when an error occurs, the combination of failed checks is literally the binary spelling of the error position. Try setting "error injection position" to 5 on the left — the syndrome should read 101, which is binary for 5.
🙋
It really does say 101! So what happens when there is no error?
🎓
Set "error injection position" to 0. The syndrome becomes 000 — position 0. Position 0 is a special value meaning "no error". That works out beautifully: if there is no error, every parity check passes and the syndrome is all zeros. The moment a single bit goes wrong, it always becomes one of 1–7 and points to the error position. The receiver just flips the bit at that spot. No retransmission — it is fixed on the spot.
🙋
It's like magic. So can this method also fix two bits that are wrong?
🎓
To be honest, the Hamming(7,4) code can fix only one bit. If two bits go wrong, the syndrome may happen to match the pattern of some other single-bit error, so it "corrects" the wrong place and adds another wound. So in practice the standard move is the extended Hamming(8,4) code, which adds one overall parity bit to give "single-error correction plus double-error detection". For more strength you use a higher-distance code like Reed-Solomon. Even so, the Hamming code is the starting point of every modern error-correcting code.
🙋
Is such an old code still used today?
🎓
Not only used — it is working this very moment. That is what ECC memory in servers is. DRAM bits occasionally flip on their own from cosmic rays and electrical noise. ECC memory uses Hamming-family circuits to correct those flips in real time, silently, without anyone noticing. The scheme Richard Hamming devised in 1950 still keeps data centers running more than 70 years later.
Frequently Asked Questions
An ordinary parity bit is a single bit and tells you only whether a single-bit error has occurred. It cannot say which bit is wrong and cannot correct anything. A Hamming(7,4) code uses three parity bits, each checking a different overlapping subset of positions. When an error occurs, the pattern of which checks fail — the syndrome — spells out the position of the flipped bit in binary. The receiver simply inverts that bit to correct it. That is the decisive difference between detection and correction.
The syndrome is the result of recomputing the three parity checks on the received word: s1 = r1⊕r3⊕r5⊕r7, s2 = r2⊕r3⊕r6⊕r7, s4 = r4⊕r5⊕r6⊕r7. Read the three bits in the order (s4 s2 s1) as a binary number and the value is exactly the position (1–7) of the erroneous bit; 0 means no error. Each parity bit verifies whether its covered positions contain an even number of ones, and the combination of failures encodes the address of the flipped bit.
No. The Hamming(7,4) code has a minimum Hamming distance of 3, so it can correct only a single-bit error. A two-bit error can be detected, but its syndrome may coincide with the pattern of some other single-bit error, causing the decoder to 'correct' the wrong position and make things worse. If two-bit correction is required, use a code with a larger distance (extended Hamming, BCH or Reed-Solomon codes). The extended Hamming(8,4) code adds one overall parity bit to achieve single-error correction plus double-error detection (SECDED).
The most famous use is ECC (error-correcting code) memory. In the DRAM of servers and workstations, Hamming-family circuits silently correct, in real time, the bit-flips caused by cosmic rays and electrical noise. Hamming codes also appear in NAND flash memory controllers, early modem communications and satellite/spacecraft telemetry — anywhere retransmission is difficult or impossible. Published by Richard Hamming in 1950, this code is the starting point of every modern error-correcting code.
Real-World Applications
ECC (error-correcting) memory: This is the most familiar and important use of Hamming codes. In the DRAM of servers, workstations and mission-critical systems, "soft errors" occur at a certain probability when a cosmic-ray (neutron) strike or electrical noise flips a memory cell. ECC memory adds 8 check bits to every 64 data bits and, with a Hamming-family SECDED scheme, corrects single-bit errors and detects double-bit errors. The user and the OS never even notice an error occurred — the computation simply continues correctly and silently.
NAND flash memory and SSDs: Flash memory cells degrade with repeated writes and reads, so bit errors increase over time. SSD and USB-drive controllers contain error-correction circuits — early products used Hamming codes, while today the more powerful BCH and LDPC codes are common. Because Hamming codes are simple, with small and fast circuits, they are still in active use in applications with low error rates.
Communications and data transmission: In early modem links, satellite/spacecraft telemetry and industrial serial communication, Hamming codes have been used for error correction in one-way links where retransmission is impossible or undesirable. The ability to fix noise-corrupted bits at the receiver alone is especially valuable in space communication, where round-trip times are long. Deep-space probes combine them with even stronger codes.
Teaching information and coding theory: The Hamming code is the first topic for learning "what an error-correcting code is" at universities worldwide. Minimum Hamming distance, syndrome decoding, generator and parity-check matrices, and the trade-off between code rate and correction power — all the basics of coding theory are packed into the compact (7,4) example. This simulator was built as a hands-on aid for experiencing those concepts.
Common Misconceptions and Pitfalls
The most common misconception is that "a Hamming code will fix any number of wrong bits". The Hamming(7,4) code can correct strictly "up to one bit". This follows from the minimum Hamming distance of 3 between codewords. A distance-3 code can do either "single-error correction" or "double-error detection", but not both at once. When a two-bit error occurs, the syndrome is non-zero, but it cannot be distinguished from some other single-bit error pattern, so the tool "corrects" a non-existent single-bit error and may even output a word that is wrong in three positions. On noisy channels you must choose a higher-distance code or layer codes together.
Next, assuming "a syndrome of 0 absolutely means no error". A syndrome becomes 0 not only when there is no error. It also becomes 0 when the error pattern happens to land exactly on another valid codeword — that is, when three or more bits flip in a conveniently matched way. This is called a "detection miss". It does not happen for one-bit or two-bit errors, but it can for three or more. A zero syndrome means "there is no one- or two-bit error", not a guarantee of being completely intact.
Finally, the oversimplification that "redundant bits are wasteful, so fewer is better". The Hamming(7,4) code has a code rate of 4/7 ≈ 0.57, meaning about 40% of what you send is check bits. That looks wasteful, but Hamming(15,11) is 11/15 ≈ 0.73 and Hamming(31,26) is 26/31 ≈ 0.84 — the longer the codeword, the smaller the redundancy fraction. However, a longer code raises the probability of "two or more errors within one codeword", and since the correction power (one bit) is unchanged, the reliability of error correction drops. Code length is a trade-off between "low redundancy" and "tolerance to errors", and should be chosen according to the channel's error rate.
How to Use
Enter a 4-bit data word (0–15) in the d1Num field; the simulator generates a Hamming(7,4) codeword by calculating parity bits p1, p2, and p4 at positions 1, 2, and 4.
Optionally inject a single-bit error by selecting a bit position (1–7) in d2Num; the codeword becomes corrupted to demonstrate error detection.
The simulator computes the syndrome (3-bit result from parity checks) which directly maps to the error position; if syndrome = 0, no error exists; if syndrome = 5, bit 5 is corrupted and auto-corrected.
Review the corrected data output and correction outcome (success/failure) in the results panel.
Worked Example
Original 4-bit data: 1011 (11 decimal). Hamming(7,4) encodes this as codeword 1101011 (7 bits). If bit 3 flips during transmission (noise in UART channel at 115200 baud), codeword becomes 1101111. Parity checks yield syndrome = 011 (binary 3), identifying bit 3 as the error. Simulator flips bit 3 back, recovering 1101011, then extracts original data 1011. Correction outcome: Success. This method adds only 3 redundancy bits to 4 data bits, achieving 57% efficiency while guaranteeing single-error correction in aerospace telemetry or industrial CAN bus protocols.
Practical Notes
Hamming(7,4) corrects exactly one bit error per codeword; multiple errors cause miscorrection—use Hamming(15,11) or Reed-Solomon for higher reliability in deep-space or NAND flash memory systems.
Parity bit positions are always powers of 2: p1 checks bits 1,3,5,7; p2 checks bits 2,3,6,7; p4 checks bits 4,5,6,7—memorize this pattern for manual encoding in exam scenarios.
Syndrome calculation is XOR-based and deterministic; syndrome value equals error position directly, enabling O(1) correction lookup in real-time embedded systems.