What Is Hamming Code? (Error-Detecting and Correcting Codes)

What Is Hamming Code? (Error-Detecting and Correcting Codes)

Verified Sources
Nov 3, 2026

Hamming code is a classic method in digital communications for adding redundant parity bits so a receiver can (1) detect corruption and (2) correct a single-bit error in each protected block. The core idea is to arrange parity checks such that each bit position influences a unique set of parity equations; that uniqueness is what makes syndrome decoding possible.

At a high level, a Hamming code takes mm data bits and produces a codeword of length n=m+rn=m+r by inserting rr parity bits. The number rr is chosen so there are enough distinct syndromes to identify which single bit (if any) flipped. For the standard single-error-correcting case, the relationship is commonly stated as: 2r≥m+r+12^r \ge m + r + 1 so there are at least m+rm+r possible nonzero syndromes (one per bit position) plus the all-zero syndrome (no error).2

Key learning terms: parity bit; syndrome; codeword; error-correction.

Footnotes

  1. Syndrome decoding / parity-check matrix concepts for Hamming codes - Overview of Hamming codes, parity-check/syndrome decoding, and single-error correction. ↩ ↩2

  2. Hamming code parameters (e.g., (7,4) code) - Example parameters and structure of Hamming codes. ↩

Hamming Codes Explained (Syndrome Decoding Intuition)

Why Hamming codes matter

In noisy channels, a transmitted bit can flip (e.g., due to interference). Hamming codes are designed so that:

  • If no error occurs, parity checks all pass, producing an all-zero syndrome.
  • If exactly one bit flips, the parity checks still satisfy a predictable pattern, producing a syndrome that points to the erroneous position.
  • With the classic Hamming design, double-bit errors are not guaranteed to be corrected and may be detected or miscorrected depending on the specific scenario and code parameters.

[CalloutBlock type="tip" title="Pro Tip" content="Try to think of the parity checks as fingerprints: a one-bit error produces a distinctive fingerprint (syndrome) that tells you which position changed."]

Relationship to parameters mm, rr, and nn

A common example is the (7,4)(7,4) Hamming code, which encodes 44 data bits into 77 total bits by adding 33 parity bits. In general, Hamming codes are linear block codes: encoding can be done using generator matrices, and decoding uses parity-check equations.

Footnotes

  1. Error-correction capability and limitations for Hamming codes - Notes on designed distance and behavior beyond single-bit errors. ↩

  2. Hamming code parameters (e.g., (7,4) code) - Example parameters and structure of Hamming codes. ↩

Core construction: parity-check equations and syndromes

A Hamming code is specified by a set of parity-check constraints. In linear form, these can be expressed using a parity-check matrix HH, where a valid codeword cc satisfies: HcT=0H c^T = 0 (operations are in modulo-2 arithmetic).
If the receiver gets a possibly corrupted word rr, the syndrome is computed as: s=HrTs = H r^T For a single-bit error in position ii, the syndrome equals the ii-th column of HH, enabling identification of the wrong bit by matching ss.

Key terms: parity-check matrix; linear block code; mod-2 arithmetic.

[CalloutBlock type="warning" title="Warning" content="Syndrome decoding is typically guaranteed for single-bit errors; behavior under multiple-bit errors is not the same. Always consider the code’s designed minimum distance."]

Footnotes

  1. Syndrome decoding / parity-check matrix concepts for Hamming codes - Overview of Hamming codes, parity-check/syndrome decoding, and single-error correction. ↩

How Hamming code single-bit correction works (syndrome decoding)

  1. 1
    Step 1

    Select parameters so the code can uniquely identify any one-bit error using rr parity bits.

  2. 2
    Step 2

    Use a parity-check matrix HH (or equivalent parity equations) so valid codewords satisfy HcT=0Hc^T=0.

  3. 3
    Step 3

    Send the full n=m+rn=m+r bits across the channel.

  4. 4
    Step 4

    Given received word rr, compute s=HrTs=Hr^T (all modulo 2).

  5. 5
    Step 5

    If ss is the all-zero vector, assume no error. Otherwise, match ss to the column of HH associated with the erroneous bit, and flip that bit.

Worked conceptual example: (7,4) Hamming code

For the (7,4)(7,4) Hamming code:

  • m=4m=4 information bits
  • r=3r=3 parity bits
  • n=7n=7 total bits

The key design property is that each of the 77 bit positions corresponds to a unique nonzero syndrome pattern (each unique column in HH), enabling correction of a single flipped bit.2

The precise mapping of data vs. parity positions (e.g., parity bits at positions 1,2,41,2,4 in a common convention) depends on the construction, but the syndrome mechanism is the same: each parity check influences specific positions so that one-bit errors are uniquely identifiable.

Footnotes

  1. Hamming code parameters (e.g., (7,4) code) - Example parameters and structure of Hamming codes. ↩ ↩2

  2. Syndrome decoding / parity-check matrix concepts for Hamming codes - Overview of Hamming codes, parity-check/syndrome decoding, and single-error correction. ↩

  3. Error-correction capability and limitations for Hamming codes - Notes on designed distance and behavior beyond single-bit errors. ↩

Hamming code capability vs. errors (designed vs. observed)

Designed for single-bit correction; multi-bit behavior varies by instance.

Common questions about Hamming codes

Roadmap to understanding Hamming codes

Error model

Step 1

Assume bit flips due to noise and decide how many errors you want to handle (classic: one)."

Redundancy design

Step 2

Choose number of parity bits rr so there are enough distinct syndromes."

Parity-check constraints

Step 3

Build HH so valid codewords satisfy HcT=0Hc^T=0."

Decoding via syndrome

Step 4

Compute s=HrTs=Hr^T and correct the bit implied by the syndrome."

Evaluate limits

Step 5

Reason about behavior for two-bit errors and compare to the code’s designed minimum distance."

Quick self-test: Hamming code essentials

1 / 5
Question · Term

What is a syndrome in Hamming decoding?

Click to reveal
Answer · Definition

The parity-check result s=HrTs=Hr^T (mod 2); it indicates whether an error occurred and (for single-bit errors) which bit.

Minimal implementation view (logic-only)

Encoding is “data + parity.” Decoding is “compute parity checks → interpret syndrome → correct.”

If you were implementing it:

  • Precompute HH (or parity-check rules).
  • To decode, compute s=HrTs=Hr^T.
  • If s≠0s\neq 0, map ss to a bit index (the matching column), then flip that bit.

This is why Hamming decoding is often described as syndrome decoding for single-error correction.

Footnotes

  1. Syndrome decoding / parity-check matrix concepts for Hamming codes - Overview of Hamming codes, parity-check/syndrome decoding, and single-error correction. ↩

Knowledge Check

Question 1 of 4
Q1Single choice

A key goal of a Hamming code is to: