Skip to content
Omnikalc

Hamming code calculator: how many parity bits do I need?

Enter the number of data bits to get the parity bits needed, the code length, the code rate, the overhead and the length of an extended SECDED code.

Updated on
Your inputs

Value out of range

Results

Parity bits needed

7

Total code length
71
Code rate
90.1%
Overhead
10.9%
Length with an extra overall parity bit (SECDED)
72
Largest data size for this many parity bits
120

A Hamming code protects data against a single flipped bit by adding a few parity bits. The Hamming code calculator takes the number of data bits and gives the parity bits needed, the total code length, the code rate, the overhead, the length of an extended SECDED code and the largest data size those parity bits could protect.

How the calculation works

  • Parity bits needed = the smallest r such that 2^r ≥ m + r + 1, where m is the number of data bits. Each parity bit covers a different subset of positions, and together they point to the position of a single error.
  • Total code length = m + r. For example, 4 data bits need 3 parity bits and give the classic (7,4) code.
  • Code rate = m ÷ (m + r), and the overhead is r ÷ m.
  • Extra overall parity bit (SECDED) = one more bit lets the code detect two errors as well as correct one, which is what most computer memory uses.

Example

For 64 data bits the smallest r with 2^r ≥ 64 + r + 1 is 7, because 2^7 = 128 is at least 72. The code is 71 bits long, with a rate of 64 ÷ 71 = 90.1% and an overhead of 7 ÷ 64 = 10.9%. Adding one overall parity bit gives the 72-bit words, called (72,64), used in ECC memory. With 7 parity bits, the code could protect up to 2^7 − 7 − 1 = 120 data bits.

Why it matters

Error-correcting codes are in memory modules, storage devices, wireless links and QR codes. Counting the parity bits is a standard exercise in computer science and electronics courses, and a quick way to see the cost of reliability in a design.

Good to know

The calculator gives the standard Hamming code that corrects one error. It does not build the code word or compute the parity values. A shortened code, where the block is smaller than the maximum for r, still needs the same number of parity bits. Codes for more errors, such as BCH, need more parity bits.

The parity bit calculator covers the simplest error check and the Shannon entropy calculator measures the information that data carries.

Frequently asked questions

What does a Hamming code do?

A Hamming code adds parity bits to a block of data so that a single flipped bit can be found and corrected. The parity bits sit at positions that are powers of two, and each one checks a different set of positions. The pattern of failed checks spells out the position of the error.

What is SECDED?

SECDED means single error correction, double error detection. It adds one overall parity bit to a Hamming code. If the checks point to an error but the overall parity is correct, two bits have flipped and the word cannot be corrected, only flagged. ECC memory modules use a (72,64) code of this kind.

Why does the overhead fall for longer blocks?

The number of parity bits grows with the logarithm of the block length, while the data grows linearly. Four data bits need 3 parity bits, which is 75% overhead, but 1,000 data bits need only 10, or 1%. Long blocks are more efficient but are more likely to contain two errors.

Can a Hamming code fix burst errors?

No. It corrects only one flipped bit per block. Bursts of errors are handled by other codes such as Reed-Solomon, or by interleaving data so that a burst is spread over several blocks, each with at most one error.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.