Hamming Code ECC Bits Calculator
Inputs
| Data bits | 8 |
|---|
Hamming Code ECC Bits Calculator
Find the minimum number of parity bits a single-error-correcting Hamming code needs to protect a given number of data bits, plus the total code-word length and the parity overhead.
Inputs
Data bits
Results
Enter a value to see results.
Results
Hamming Code ECC Bits
A Hamming code protects a block of data by adding a handful of parity bits. When one bit later flips, the pattern of failed parity checks names the exact position that changed, so a decoder can flip it back. The only design question is how many parity bits a block of a given size needs.
The minimum-bits condition
Let be the number of data bits and the number of parity bits. The parity bits together form an -bit syndrome, which can take distinct values. Each of the code-word positions must have its own non-zero syndrome so the decoder can point at the bit that flipped, and one value is reserved to mean "no error." That gives the single-error-correcting (SEC) condition:
2r≥m+r+1Because appears on both sides, there is no closed-form solution. The required parity count is simply the smallest that satisfies the inequality, found by testing in turn.
Worked example: 8 data bits
Take and test each candidate:
| 2 | 4 | 11 | no |
| 3 | 8 | 12 | no |
| 4 | 16 | 13 | yes |
The first row that holds is , so 8 data bits need 4 parity bits:
24=16≥8+4+1=13The full code word is
n=m+r=8+4=12 bitsand the parity overhead is
O=nr=124≈33.3%Overhead shrinks as blocks grow
The parity count grows roughly like , so larger blocks amortise the check bits over far more data. The table lists common block sizes.
| Data bits | Parity bits | Code word | Overhead |
|---|---|---|---|
| 1 | 2 | 3 | 66.7% |
| 4 | 3 | 7 | 42.9% |
| 8 | 4 | 12 | 33.3% |
| 11 | 4 | 15 | 26.7% |
| 16 | 5 | 21 | 23.8% |
| 26 | 5 | 31 | 16.1% |
| 32 | 6 | 38 | 15.8% |
| 57 | 6 | 63 | 9.5% |
| 64 | 7 | 71 | 9.9% |
| 247 | 8 | 255 | 3.1% |
The classic (7, 4) Hamming code — 4 data bits in a 7-bit word — sits on the third-from-top row, and the (15, 11) code on the fourth.
Parity-bit placement
In the standard layout the parity bits occupy the power-of-two positions 1, 2, 4, 8, 16, … and the data bits fill the rest. A parity bit at position covers exactly the positions whose index has bit set, so the set of failing checks reads out directly as the binary address of the flipped bit. Counting the power-of-two positions up to gives the same this page computes, which is why the placement scheme and the minimum-bits condition always agree.
SEC versus SECDED
The condition above is for a single-error-correcting code, which corrects any one-bit error but cannot tell a genuine two-bit error apart from a one-bit one. Adding a single overall parity bit across the whole code word yields a single-error-correcting, double-error-detecting (SECDED) code: it still corrects any single-bit error and additionally flags — without correcting — any double-bit error. For SECDED, add one bit to both the parity count and the total length. Memory marketed as "ECC" typically uses SECDED, for example 64 data bits guarded by 8 check bits.
Related estimates
To compare two equal-length bit strings and count how many positions differ — the metric that sets how many errors a code can catch — see the Hamming Distance Calculator. For a different error-detection scheme that appends a checksum instead of position-addressing parity, the CRC Checksum Calculator computes cyclic redundancy checks.
Frequently Asked Questions (FAQ)
What are parity bits in a Hamming code?
Parity bits, also called check bits, are extra bits added to a block of data so that a decoder can detect and correct errors. In a Hamming single-error-correcting (SEC) code, each parity bit covers a specific, overlapping subset of the data positions. When a bit flips, the pattern of parity checks that fail — the syndrome — spells out, in binary, the exact position of the flipped bit, so the decoder can flip it back.
The number of parity bits r for m data bits is the smallest r that satisfies 2^r ≥ m + r + 1. For 8 data bits this gives r = 4, producing a 12-bit code word.
What is the difference between SEC and SECDED?
A single-error-correcting (SEC) Hamming code corrects any single-bit error in a code word but cannot reliably tell a double-bit error apart from a single-bit one. Single-error-correcting, double-error-detecting (SECDED) adds one more overall parity bit on top of the SEC code. That extra bit lets the decoder correct any single-bit error and also detect (though not correct) any double-bit error.
This calculator reports the parity bits for the SEC form. For SECDED, add one bit to the parity count and to the total code-word length. Server memory that reports "ECC" often uses a SECDED code — for example, 64 data bits protected by 8 check bits.
Why is the inequality 2^r ≥ m + r + 1 rather than 2^r ≥ m + r?
The r parity bits together produce an r-bit syndrome, which can take 2^r different values. Each of the n = m + r code-word positions needs its own non-zero syndrome so the decoder can name the position that flipped. One more value — the all-zero syndrome — is reserved to mean "no error detected." That reserved value is the source of the + 1, so the syndrome must cover m + r positions plus the no-error case: 2^r ≥ (m + r) + 1.
Where do the parity bits go in the code word?
In the classic Hamming layout, the parity bits sit at the power-of-two positions — 1, 2, 4, 8, 16, and so on — while the data bits fill the remaining positions. Placing each parity bit at position 2^k makes it responsible for exactly the positions whose index has bit k set, which is what lets the failing checks read off as the binary address of the erroneous bit.
The count of power-of-two positions up to n is the same r this calculator returns, which is why the placement and the minimum-bits formula agree.