Productivity and Utilities

Hamming Code Encoder and Decoder

Type data bits to encode them, flip positions to simulate errors, and watch the syndrome point at the damage.

Your numbers

What to do

Example data. Zeros and ones, 1 to 64 bits.

Positions counted from 1 at the left, such as 5 or 3, 6. Simulates errors on the way.

Lets the code detect two errors as well as correct one.

Result

Codeword

0110011

4 data bits plus 3 parity bits.

Syndrome
0
Data bits
1011
Corrected word
0110011
Codeword sent
0110011
Verdict
No error found

Position by position

PositionRoleSentReceivedCorrected
1Parity P1000
2Parity P2111
3Data D1111
4Parity P4000
5Data D2000
6Data D3111
7Data D4111
How this was calculated
  1. Positions are numbered from 1. Parity bits sit at positions 1, 2, 4, 8 and so on. Data bits fill the other positions in order. Each parity bit makes the number of 1s among the positions whose number contains that power of two even.
  2. To check a word, add up (XOR) the position numbers of every 1 bit. That sum is the syndrome. A syndrome of 0 means every parity check passes. A nonzero syndrome is the position of a single flipped bit, which is flipped back.
  3. The plain code corrects any single error but cannot tell two errors from one, so a double error is silently "corrected" to the wrong word.

Calculated using SumPanda.com · https://sumpanda.com/hamming-code-encoder-decoder/

Results are estimates for general information. Verify important figures before relying on them.

Next step

How to use the hamming code encoder and decoder

  1. Choose Encode data bits, or Check a received word if you already have a word to test.
  2. To encode, type the data bits (1 to 64 zeros and ones). To simulate errors, list positions to flip, counting from 1 at the left.
  3. Tick the extended code if you want the extra overall parity bit that can detect two errors.
  4. Read the codeword, the syndrome, the verdict, the corrected word and the data bits, with a table showing every position.

Formula

parity bits sit at positions 1, 2, 4, 8, ...; data bits fill the rest in order

parity bit 2^i makes the 1s at positions whose number has bit i even

syndrome = XOR of the positions of all 1 bits; a nonzero syndrome is the position of a single error

For k data bits the number of parity bits r is the smallest with 2^r at least k + r + 1. The extended code adds one more bit at the end that makes the whole word even.

Four data bits

The data 1011 goes to positions 3, 5, 6 and 7. Parity bit 1 covers positions 1, 3, 5 and 7: 1 + 0 + 1 = even, so it is 0. Parity bit 2 covers 2, 3, 6 and 7: 1 + 1 + 1 gives 1. Parity bit 4 covers 4, 5, 6 and 7: 0 + 1 + 1 is even, so 0. The codeword is 0110011.

If position 5 is flipped in transit, the received word is 0110111. The positions of its 1 bits are 2, 3, 5, 6 and 7, and 2 XOR 3 XOR 5 XOR 6 XOR 7 = 5, so the syndrome is 5. Flipping position 5 back restores 0110011 and the data 1011.

What the code can and cannot do

A plain Hamming code corrects any single flipped bit but cannot tell a double error from a single one, so two errors are silently "corrected" to the wrong word. The extended code adds an overall parity check: a nonzero syndrome with a failing overall check means one error and can be corrected, while a nonzero syndrome with a passing overall check means two errors, which are detected but not corrected. This design is called SECDED.

Memory modules and storage systems use codes in this family. For error detecting checksums, see the CRC Calculator, and to work with raw bits use the Bitwise Calculator.

Valid word lengths

Only certain lengths are complete Hamming words: 3, 5, 6, 7, 9 to 15, 17 to 31 and so on. In check mode the page tells you which lengths are possible if yours is not one of them. A word of a shortened code, such as 5 bits for 2 data bits, uses the same position rules with the unused positions left out.

Assumptions and limits

  • Parity is even, positions count from 1 at the left, and the extra bit of the extended code is placed last.
  • Data may have 1 to 64 bits; spaces and underscores in the bit strings are ignored.
  • Flip positions beyond the length of the word are rejected.
  • A pattern that matches no single position, possible in shortened codes, is reported as not fixable.
  • The tests flip every kind of position in hundreds of words and compare with a separate parity-check matrix.

Formulas reviewed October 10, 2026. See the calculation methodology for how SumPanda rounds, tests and sources its formulas.

Frequently asked questions

Why are parity bits at powers of two?

The position numbers in binary then show which parity bits cover them, so the syndrome reads out the position of the error directly.

What does a syndrome of 0 mean?

Every parity check passes. That means no error, or an error pattern that the code cannot see, such as three flips that happen to form another codeword.

Why add the extended bit?

It lets the decoder separate one error, which it can fix, from two, which it can only report.

Is Hamming (7,4) the only Hamming code?

No. It is the best known case, with 4 data and 3 parity bits. The same rules give (15,11), (31,26) and so on.