---
title: "Short note: Hamming codes"
subject: "Data Communication"
chapter: 8
key: "semester_5/data_communication:hamming-codes-short-note"
source: https://www.bctengineer.com/q/semester_5/data_communication/hamming-codes-short-note
site: BCT Engineering
---

# Short note: Hamming codes

Data Communication · Chapter 8: Information Theory and Coding

- Asked in: 2078 Bhadra, 4 marks
- Video: [Hamming Code | Error Detection](https://www.youtube.com/watch?v=1A_NcXxdoCc) — Neso Academy
- Answer checked by Claude Sonnet 5.5 on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/data_communication/hamming-codes-short-note
- Whole chapter: https://www.bctengineer.com/md/semester_5/data_communication/chapter-8

## Question

Write a short note on Hamming codes.

## Short answer

Hamming codes are linear block codes with d_min=3, correcting single-bit errors. For r parity bits, n=2^r−1, k=n−r. Parity bits at powers of 2 check overlapping groups; the syndrome indicates error position. Used in ECC memory.

## Answer

**Hamming codes** are linear block codes that can **detect up to two-bit errors or correct single-bit errors**. For r parity bits, the code length is n = 2ʳ − 1 and the message length is k = n − r, e.g. (7,4) with r = 3 and (15,11) with r = 4. The minimum distance is 3 (an extra overall parity bit gives d_min = 4, called SECDED: single-error correction, double-error detection).

#### Construction (7,4)
Parity bits are placed at positions that are powers of 2 (1, 2, 4); data bits go at positions 3, 5, 6, 7:

```text
 position : 1  2  3  4  5  6  7
 bit      : p1 p2 d3 p4 d5 d6 d7
```
Each parity bit checks the positions whose binary index contains it (even parity):
- p1 covers 1, 3, 5, 7
- p2 covers 2, 3, 6, 7
- p4 covers 4, 5, 6, 7

Example: data 1011 (d3 d5 d6 d7 = 1,0,1,1):
p1 = 1⊕0⊕1 = 0, p2 = 1⊕1⊕1 = 1, p4 = 0⊕1⊕1 = 0 → codeword **0110011**.

#### Error correction
The receiver recomputes the three checks c4 c2 c1. The binary number they form is the **position of the erroneous bit** (0 means no error). If bit 5 is received wrongly (0110011 → 0110111): c1 = 1, c2 = 0, c4 = 1 → 101 = 5, so flip bit 5.

Hamming codes are used in computer memory (ECC RAM) and data storage.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. For r parity bits, what are the code length and message length?
   A. n = 2r, k = r
   B. n = 2^r - 1, k = n - r
   C. n = r^2, k = r
   D. n = 2^r, k = 2^r - r
   Answer: B. Hamming codes have n = 2^r - 1; r = 3 gives (7,4). (Key point: Length formula)

2. In the (7,4) Hamming code, where are parity bits placed?
   A. Positions 5, 6, 7
   B. Positions 1, 2, 3
   C. Positions that are powers of 2 (1, 2, 4)
   D. Positions 4, 5, 6
   Answer: C. Parity bits sit at positions 1, 2, 4 and data bits at 3, 5, 6, 7. (Key point: Parity bit positions)

3. How does the receiver find the erroneous bit?
   A. The binary number formed by the three checks c4 c2 c1 gives its position
   B. It counts the 1s in the word
   C. It retransmits the word
   D. It compares with the previous word
   Answer: A. The recomputed checks form the position of the error; 101 = 5 means bit 5 is flipped, and 0 means no error. (Key point: Locating errors)

## Related in Data Communication

- [Hamming codes and their properties](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Ahamming-code-properties) — Data Communication, chapter 8
- [Redundancy, Hamming distance, linear vs cyclic](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Aredundancy-hamming-linear-cyclic) — Data Communication, chapter 8

## Related in other subjects

- [Convolutional vs block codes; (7,4) cyclic code for 1011](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Aconv-vs-block-cyclic-7-4-1011) — Communication Systems, chapter 8, asked 2×
