# Hamming Code Calculator (Encode, Detect, Correct)

URL: https://speedycalculator.com/calculators/other/hamming-code/
Last updated: 2026-10-30

> The Hamming code calculator encodes binary data with Hamming(7,4), (15,11), (31,26) and larger codes or the (3,1) repetition code, and checks received codewords: it computes the syndrome, corrects any single-bit error and extracts the data. Extended SECDED parity and two bit layouts are supported.

## Inputs

- Code
- What to do
- Binary message — Encoding: any number of data bits. Checking/decoding: complete codewords; spaces are ignored.
- Bit layout
- Extra overall parity bit (SECDED)

## Results

- Result
- Status
- Data bits after correction
- Errors corrected
- Codewords
- Code rate (data share)
- Parity bits per codeword
- Minimum Hamming distance
- Block by block
- Note

## Formula

```
n = 2ʳ − 1 bits per codeword, k = n − r data bits, r parity bits at positions 1, 2, 4, 8 …
Parity bit p = XOR of all positions whose index has that bit set · Syndrome = XOR of the positions of all 1s (0 = no error, otherwise the position of the flipped bit)
```

## Explanation

Richard Hamming invented his codes at Bell Labs in 1950, frustrated that the relay computer kept stopping on weekends whenever it detected an error it could not fix. His idea was to add a few parity bits, each checking a different overlapping group of positions, so that the pattern of failed checks – the syndrome – spells out in binary exactly which bit was flipped. Flip it back and the data is repaired.

With r parity bits a Hamming code protects 2ʳ − 1 − r data bits: Hamming(7,4) adds 3 parity bits to 4 data bits, Hamming(15,11) 4 to 11, and Hamming(255,247) only 8 to 247, so longer codes are more efficient but can still fix only one error per block. Every pair of codewords differs in at least 3 bits, which is why one error can be corrected or two errors detected (but not both). Adding one overall parity bit gives the extended SECDED code (single error correction, double error detection) used in ECC memory.

There are two common ways to arrange the bits. The classic layout puts parity bits at the power-of-two positions 1, 2, 4, 8 …, which makes the syndrome equal the error position. The systematic layout, used with generator matrices, sends the data bits first and the parity bits after them. Pick the one your course or system uses – both protect the data equally well.

### How to use the Hamming Code Calculator

- **Code**
- **What to do**
- **Binary message** — Encoding: any number of data bits. Checking/decoding: complete codewords; spaces are ignored.
- **Bit layout**
- **Extra overall parity bit (SECDED)**

Everything is calculated in your browser, so results appear instantly and nothing you type is sent to a server.

### How it works

Encoding splits the message into k-bit blocks (padding the last one with zeros), places the data bits in the non-power-of-two positions and sets each parity bit so its group has even parity. Checking recomputes the syndrome for each n-bit block; a non-zero syndrome identifies the flipped bit, which is inverted. With SECDED, the overall parity distinguishes single errors (corrected) from double errors (reported).

### Worked example

Encode the 8-bit message **11010011** with Hamming(7,4), classic layout. Block 1 = 1101: positions 3, 5, 6, 7 hold the data; p1 checks 1, 3, 5, 7 → 1, p2 checks 2, 3, 6, 7 → 0, p4 checks 4–7 → 0, giving 1010101. Block 2 = 0011 gives 1000011. If the first codeword is received as 1010001, the syndrome is 101 = 5, so bit 5 is flipped back and the data 1101 recovered.

### Hamming code sizes

CodeParity bits rData bits kCode rate(3,1)2133.3%(7,4)3457.1%(15,11)41173.3%(31,26)52683.9%(63,57)65790.5%(127,120)712094.5%(255,247)824796.9%

## Worked example

Inputs — Code: Hamming(7,4); What to do: Encode data; Binary message: 11010011; Bit layout: Classic – parity bits at positions 1, 2, 4, 8 …; Extra overall parity bit (SECDED): No.

Results — **Result = 1010101 1000011**; Status = 2 codewords of 7 bits; Codewords = 2; Code rate (data share) = 57.1 %; Parity bits per codeword = 3; Minimum Hamming distance = 3.

## Key terms

- **Parity bit**: An extra bit that makes the number of 1s in a group even (or odd).
- **Syndrome**: The result of the parity checks; it locates a single error.
- **Code rate**: Data bits ÷ total bits, k/n.
- **SECDED**: Single error correction, double error detection – Hamming plus an overall parity bit.

## FAQ

**How many errors can a Hamming code correct?**
One per codeword. The plain code can alternatively detect two errors; the extended SECDED version corrects one and detects two at the same time.

**How do I encode 1101 with Hamming(7,4)?**
Classic layout: p1 = 1⊕1⊕1 = 1, p2 = 1⊕0⊕1 = 0, p4 = 1⊕0⊕1 = 0, giving 1010101. Systematic layout gives 1101 100.

**What is the syndrome?**
The XOR of the positions of all 1 bits (equivalently H·cᵀ). Zero means no error; otherwise, in the classic layout, it is the position of the wrong bit.

**What is the code rate of Hamming(7,4)?**
4/7 ≈ 57%; Hamming(15,11) reaches 73% and Hamming(255,247) 96.9%.

**What happens with two errors?**
The plain code “corrects” the wrong bit and produces a different valid codeword. Use SECDED to detect this case.

**Why is Hamming(3,1) a repetition code?**
With r = 2 there is only one data bit, and both parity bits copy it: 1 → 111, 0 → 000. Majority vote fixes one error.

**Where are Hamming codes used?**
ECC RAM, some flash memory and satellite links, and as a classic teaching example of error-correcting codes.


## Sources

- [R. W. Hamming – Error detecting and error correcting codes, Bell System Technical Journal 29 (1950)](https://doi.org/10.1002/j.1538-7305.1950.tb00463.x)
- [Wikipedia – Hamming code](https://en.wikipedia.org/wiki/Hamming_code)
