Bits flipped
Syndrome
Received
Data bits per bit sent

More about error-correcting codes

Error-correcting code simulator

Every message that travels through a wire, the air or a scratched disc picks up errors: bits flip from 0 to 1 and back. An error-correcting code adds a few carefully chosen extra bits so the receiver can find and repair the damage without asking again. Type four data bits, see Richard Hamming's code turn them into seven, flip any bit you like, and watch three overlapping circles point straight at the error. Then send a whole message through a noisy channel and compare what arrives with and without the code. Type four data bits, such as 1011, and the app adds three parity bits to make a 7-bit Hamming codeword. Click any bit, in the circles or in the row, to flip it as noise would; click it again to flip it back. Each circle must hold an even number of 1s: the circles that fail point to the wrong bit, and the decoder flips it back. Switch on the extra parity bit to see two errors detected instead of wrongly corrected. Below, send a text through a noisy channel with and without the code.

How it works

  1. Type four data bits and see the seven-bit codeword with its three parity bits, in circles and in a row.
  2. Click bits to flip them and watch which circles fail, where the syndrome points and whether the decoder repairs the word.
  3. Switch on the extra parity bit, then send a message through the noisy channel and compare the results with and without the code.

How the Hamming code finds an error

The seven bits are numbered 1 to 7. Bits 1, 2 and 4 are parity bits, and the four data bits sit at 3, 5, 6 and 7. Parity bit 1 makes the number of 1s even among positions 1, 3, 5 and 7, the positions whose number in binary ends in 1; bit 2 does the same for 2, 3, 6 and 7, and bit 4 for 4, 5, 6 and 7. Drawn as three overlapping circles, every bit sits in exactly the circles that check it. When one bit flips, the circles containing it turn odd. Read the failing checks as a binary number, the syndrome, and you get the position of the wrong bit.

What one extra bit buys

With two flipped bits the syndrome points at a third, innocent bit, and the decoder makes things worse. Adding an eighth bit that makes the whole word even fixes that: one error changes the overall parity, two errors leave it even while some circles fail. The extended code, known as SECDED for single error correction, double error detection, corrects one error and reliably detects two, so the receiver can ask for that block again. It is the code used in the ECC memory of servers. Over a noisy channel, the code turns many scattered errors into a few, as long as two flips rarely land in the same block.

Frequently asked questions

Why are the parity bits at positions 1, 2 and 4?

Because those are the powers of two, and each has a single 1 in binary. Parity bit 2ᵏ checks every position whose binary number has a 1 in place k. A flipped bit at position 6 = 110 in binary breaks the checks of 2 and 4 and leaves 1 alone, and the failing checks spell out 110, the position itself.

How much does the protection cost?

The (7,4) code sends 7 bits for every 4 data bits, a rate of 4/7: 75% extra. The extended code sends 8 for 4, double. Longer Hamming codes are cheaper: 15 bits carry 11 data bits, 31 carry 26. Modern codes such as LDPC and polar codes, used in Wi-Fi and 5G, come very close to the best rate that Claude Shannon proved possible in 1948.

What happens with three errors?

The plain Hamming code can be fooled completely: any two codewords differ in at least three bits, so three flips can turn one valid codeword into another, and no check fails at all. The app reports this as an error not noticed. Real systems keep such cases rare by choosing a code strong enough for the noise level.

Where are error-correcting codes used?

Almost everywhere digital data travels or is stored: ECC computer memory, hard disks and SSDs, CDs, DVDs and Blu-ray discs, QR codes, which stay readable with a part torn off, mobile phones and Wi-Fi, digital television and messages from space probes such as Voyager, which still send data from beyond the Solar System.

Is my message sent anywhere?

No. The noisy channel is simulated in your browser, and your message and settings stay in this browser's local storage.

Ready to try it?

Open PictorX in your browser — no install, no credit card required to start.

Go to Editor