Hamming Code Simulator
Encode data with Hamming (7,4) or (12,8), flip a bit and watch the parity checks find and correct it.
1. Data bits
Click to change the data. Parity bits go at positions that are powers of 2 (1, 2, 4, 8); data fills the rest.
2. Encoded codeword (even parity)
Hover a parity bit to see which positions it checks: every position whose binary number has that bit set.
| P1 | checks positions 1, 3, 5, 7 | = 1 ⊕ 0 ⊕ 1 → 0 |
| P2 | checks positions 2, 3, 6, 7 | = 1 ⊕ 1 ⊕ 1 → 1 |
| P4 | checks positions 4, 5, 6, 7 | = 0 ⊕ 1 ⊕ 1 → 0 |
3. Received codeword
Click one bit to flip it (a 1-bit transmission error).
Check P1: ones = 2 → even ✓ (0)
Check P2: ones = 4 → even ✓ (0)
Check P4: ones = 2 → even ✓ (0)
4. Locate & correct
Recovered data: 1011 ✓ matches the original
About This Simulation
This Hamming code simulator encodes 4 or 8 data bits by placing parity bits at positions that are powers of two. You can flip any bit of the received codeword and watch the parity checks combine into a syndrome that points to the exact bit to correct.
Features
- Hamming (7,4) and Hamming (12,8) codes
- Codeword with parity (P) and data (D) positions labelled
- Hover a parity bit to see the positions it checks
- Flip any bit to simulate a transmission error
- Syndrome calculation, error location and corrected data
Topics covered
- Hamming Code
- Error Correction
- Parity Bits
- Syndrome
- Forward Error Correction
Explanation
A Hamming code is an error-correcting code. It adds several parity bits so that a single-bit error can be both detected and located, letting the receiver correct it without asking for the data again. Each parity bit checks a different, overlapping group of positions.
How it works
- Number the bit positions from 1. Positions that are powers of two (1, 2, 4, 8) hold parity bits; the rest hold data.
- Parity bit P1 checks every position whose binary number ends in 1 (1, 3, 5, 7, …); P2 checks positions with the 2s bit set (2, 3, 6, 7, …); P4 checks positions with the 4s bit set, and so on.
- Each parity bit is set so that its group has even parity.
- The receiver recalculates every check. The positions of the failed checks are added together to give the syndrome.
- A syndrome of 0 means no error; otherwise it is the position of the wrong bit, which is flipped to correct it.
Why it matters
Hamming codes are the basis of error-correcting (ECC) memory and are covered in computer networks and data communications courses. They show how carefully placed redundancy allows forward error correction.
Frequently Asked Questions
How many parity bits does a Hamming code need?
With r parity bits you can protect up to 2ʳ − r − 1 data bits. 3 parity bits protect 4 data bits (7,4); 4 parity bits protect up to 11 data bits.
Can Hamming codes correct two errors?
No. A basic Hamming code corrects one error. With two errors the syndrome points to the wrong bit. An extra overall parity bit (SECDED) can detect, but not correct, two errors.
What is the syndrome?
The sum of the positions of the parity checks that fail. It gives the position of the incorrect bit, or 0 if there is no error.
Related Simulations
Data Representation
Error Detection Simulator
Flip bits in transit and see how parity bits, parity blocks, checksums and majority voting detect or correct the errors.
Number Systems
Bitwise Operations Simulator
Apply AND, OR, XOR, NOT, logical and arithmetic shifts and rotations to 8-bit values, and use masks to set, clear and test bits.
Data Communications
Digital Signal Encoder & Scrambling Visualizer
Turn a bit string into a signal with NRZ-L, NRZ-I, Manchester, AMI, MLT-3 and more, then scramble it with B8ZS or HDB3.
Data Representation
Bitmap File Size Simulator
Calculate image file size from resolution and colour depth, with a live preview of how colour depth changes the image.

