Block Coding & Hamming Distance
Block coding adds structured error-checking bits to a data word. The reliability of a block code relies heavily on its Minimum Hamming Distance ($d_{min}$), which defines the minimum number of bit flips required to accidentally turn one valid codeword into another valid codeword.
Learning Goals
- Introduction to Block Coding: Mapping $k$-bit datawords into $n$-bit codewords ($n > k$).
- Error Detection vs. Error Correction mechanisms in block codes.
- Hamming Distance: Definition, calculating distance between two binary words, and Minimum Hamming Distance ($d_{min}$).
- Geometric representation and conditions for detecting ($s$ errors) and correcting ($t$ errors).
- Compute the Hamming distance between any two given binary sequences.
- Mathematically prove how many errors a code can detect or correct using the formulas:$$d_{min} = s + 1$$$$d_{min} = 2t + 1$$
In the Data Link Layer of computer networks, block coding adds controlled redundancy so that transmission errors can be detected and, in some schemes, corrected before data is delivered upward.2 A source message is divided into -bit datawords and each dataword is mapped to an -bit codeword with . The added bits carry no new payload information, but they create structure in the code space that helps the receiver recognize corruption.2
A central metric in this structure is the Hamming distance, defined as the number of differing bit positions between two binary words of equal length.2 For binary vectors and , it can be computed by XOR and bit counting:
where is the number of s in the result, also called the Hamming weight.2 The design quantity that matters most is the minimum Hamming distance , because it determines how many errors the code can reliably detect or correct.3
In network-theory context, block coding is not merely abstract algebra: it expresses the tradeoff among reliability, bandwidth efficiency, and decoder complexity. A higher code rate preserves more bandwidth, while a larger improves resilience to noise. This section develops the mapping from datawords to codewords, the difference between error detection and error correction, the geometry of Hamming space, and the formal results
which characterize guaranteed detection of errors and guaranteed correction of errors.3
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩ ↩2 ↩3 ↩4 ↩5
-
Data Link Layer - Data link layer notes explaining datawords, codewords, redundancy, and minimum-distance rules. ↩ ↩2 ↩3 ↩4 ↩5
-
Introduction to binary block codes - MIT material on Hamming space, spheres, and geometric interpretation of block codes. ↩
-
Minimum Hamming Distance - GeeksforGeeks - Accessible explanation of Hamming weight, Hamming distance, and examples. ↩ ↩2
-
Codewords and Hamming Distance • Error Detection: parity - MIT - MIT notes summarizing how minimum distance determines detectable and correctable errors. ↩ ↩2 ↩3
Hamming Distance and Minimum Hamming Distance
Why this matters in the Data Link Layer
Frames can be corrupted by noise, interference, attenuation, or synchronization issues. Block coding adds structured redundancy so a receiver can detect invalid bit patterns and, in stronger codes, infer the most likely transmitted codeword.2
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩
-
Data Link Layer - Data link layer notes explaining datawords, codewords, redundancy, and minimum-distance rules. ↩
Block Coding Model
A block code can be described as an scheme: each -bit dataword is transformed into an -bit codeword, where and is the number of redundant bits. Because there are possible datawords, an encoder must assign one valid codeword to each of those inputs. Not every -bit word is valid; only the selected set of codewords belongs to the code. This restriction is what makes error detection possible.2
For example, consider a simple code:
| Dataword | Codeword |
|---|---|
Only four of the eight possible -bit patterns are valid. If the receiver gets , it can immediately declare an error because is not one of the legal codewords. This is the essence of error detection.
A stronger code may also support error correction by choosing the valid codeword nearest to the received word in Hamming distance.2 In that case, codewords must be separated more widely so that the “regions of influence” around them do not overlap.2
A useful rate measure is
which quantifies efficiency. Higher redundancy lowers rate but can increase and therefore reliability.
Footnotes
-
Data Link Layer - Data link layer notes explaining datawords, codewords, redundancy, and minimum-distance rules. ↩ ↩2 ↩3 ↩4
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩ ↩2 ↩3
-
Codewords and Hamming Distance • Error Detection: parity - MIT - MIT notes summarizing how minimum distance determines detectable and correctable errors. ↩ ↩2
-
Introduction to binary block codes - MIT material on Hamming space, spheres, and geometric interpretation of block codes. ↩
How to Compute Hamming Distance Between Two Binary Sequences
- 1Step 1
The two binary sequences must have the same number of bits; otherwise the Hamming distance is not defined in the standard block-coding sense.2
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩
-
Minimum Hamming Distance - GeeksforGeeks - Accessible explanation of Hamming weight, Hamming distance, and examples. ↩
-
- 2Step 2
Inspect each bit pair from left to right and note every position at which the bits differ.
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩
-
- 3Step 3
XOR the two sequences. Every resulting marks a differing position, while every marks a matching position.2
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩
-
Data Link Layer - Data link layer notes explaining datawords, codewords, redundancy, and minimum-distance rules. ↩
-
- 4Step 4
The total number of differing positions is the Hamming distance.2
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩
-
Minimum Hamming Distance - GeeksforGeeks - Accessible explanation of Hamming weight, Hamming distance, and examples. ↩
-
- 5Step 5
A larger distance means the two words are more separated in Hamming space, which generally improves distinguishability under noise.2
Footnotes
-
Introduction to binary block codes - MIT material on Hamming space, spheres, and geometric interpretation of block codes. ↩
-
Codewords and Hamming Distance • Error Detection: parity - MIT - MIT notes summarizing how minimum distance determines detectable and correctable errors. ↩
-
Worked Examples of Hamming Distance
Let us compute distances directly.
Example 1
For and :
The XOR result has two s, so
This example is standard in block-coding discussions.2
Example 2
For and :
The XOR result contains three s, hence
Again, the distance equals the number of differing bit positions.2
Example 3
For and :
The XOR result has three s, so
For an entire code, we calculate all pairwise distances among valid codewords and choose the smallest. That smallest value is .2 If a code has codewords , the pairwise distances are all , so
In this code, every valid codeword is separated from every other valid codeword by at least two bit changes, so any single-bit corruption moves a transmitted codeword to an invalid word rather than another valid one.
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩ ↩2 ↩3
-
Data Link Layer - Data link layer notes explaining datawords, codewords, redundancy, and minimum-distance rules. ↩ ↩2 ↩3 ↩4
Fast exam shortcut
To compute Hamming distance quickly, XOR the two bit strings and count the s. This avoids manual comparison and directly matches the formal definition .2
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩
-
Minimum Hamming Distance - GeeksforGeeks - Accessible explanation of Hamming weight, Hamming distance, and examples. ↩
Minimum Hamming Distance and Its Meaning
The minimum distance is the most important design parameter of a block code because the worst-separated pair of valid codewords determines the code’s guaranteed performance.2 Formally, if is the set of valid codewords, then
Interpretation:
- If valid codewords are too close, a small number of bit flips may transform one valid codeword into another, making reliable detection impossible.
- If valid codewords are far apart, more corruption is needed before ambiguity arises.2
A classic relation states:
- To detect up to errors in all cases, a code must satisfy
- To correct up to errors in all cases, a code must satisfy
These are often written in exact guaranteed-capability form as
The equalities and describe the threshold values for exact guaranteed detection and correction limits.2
This explains familiar cases:
| Guaranteed detection | Guaranteed correction | |
|---|---|---|
| errors | errors | |
| error | errors | |
| errors | error | |
| errors | error | |
| errors | errors |
The correction count grows more slowly because correction requires not only noticing that an error occurred, but deciding which original codeword was sent.2
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩ ↩2 ↩3 ↩4
-
Data Link Layer - Data link layer notes explaining datawords, codewords, redundancy, and minimum-distance rules. ↩
-
Codewords and Hamming Distance • Error Detection: parity - MIT - MIT notes summarizing how minimum distance determines detectable and correctable errors. ↩ ↩2 ↩3
-
Introduction to binary block codes - MIT material on Hamming space, spheres, and geometric interpretation of block codes. ↩
Guaranteed Capability vs. Minimum Hamming Distance
Comparison of detectable and correctable error counts implied by .2
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩
-
Codewords and Hamming Distance • Error Detection: parity - MIT - MIT notes summarizing how minimum distance determines detectable and correctable errors. ↩
Geometric View: Hamming Space, Spheres, and Decoding Regions
All binary words of length can be viewed as points in an -dimensional Hamming space.2 Valid codewords occupy selected points in this space, and the Hamming distance measures how many coordinate changes are needed to move from one point to another.
For correction, we imagine a Hamming sphere of radius around each valid codeword. Every received word inside that sphere is decoded to the center codeword.2 To guarantee correction of errors, spheres of radius around distinct codewords must not overlap. If they overlapped, some received word would be within distance of two different codewords, causing ambiguity.2
For detection only, overlap is not the issue. Instead, we need every pattern of up to bit errors to move the transmitted codeword outside the set of all valid codewords.2 Therefore, no two codewords may be closer than .
This geometric picture is especially valuable because it turns an algebraic rule into an intuitive one:
- Detection means corrupted words should not land on another legal codeword.
- Correction means corrupted words should remain closest to the true codeword.2
Footnotes
-
Introduction to binary block codes - MIT material on Hamming space, spheres, and geometric interpretation of block codes. ↩ ↩2 ↩3 ↩4 ↩5
-
Hamming Metric and the Minimum Distance - UCSD notes providing proof ideas for correction capability via triangle inequality and Hamming spheres. ↩ ↩2 ↩3
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩ ↩2
-
Data Link Layer - Data link layer notes explaining datawords, codewords, redundancy, and minimum-distance rules. ↩
-
Codewords and Hamming Distance • Error Detection: parity - MIT - MIT notes summarizing how minimum distance determines detectable and correctable errors. ↩
Proof Idea for Error Detection: Why $d_{min}=s+1$
- 1Step 1
This means every pair of distinct valid codewords differs in at least bit positions.2
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩
-
Data Link Layer - Data link layer notes explaining datawords, codewords, redundancy, and minimum-distance rules. ↩
-
- 2Step 2
Suppose a codeword is sent and at most bit errors occur during transmission.
- 3Step 3
The received word differs from in at most positions, so .
- 4Step 4
If were some other valid codeword , then would have to be at most , contradicting the definition that all distinct codewords are at least apart.
- 5Step 5
Thus guaranteed detection of all patterns of up to errors requires , equivalently .2
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩
-
Codewords and Hamming Distance • Error Detection: parity - MIT - MIT notes summarizing how minimum distance determines detectable and correctable errors. ↩
-
Proof Idea for Error Correction: Why $d_{min}=2t+1$
- 1Step 1
The decoder selects the valid codeword with smallest Hamming distance from the received word, which is the standard minimum-distance decoding rule.2
Footnotes
-
Codewords and Hamming Distance • Error Detection: parity - MIT - MIT notes summarizing how minimum distance determines detectable and correctable errors. ↩
-
Hamming Metric and the Minimum Distance - UCSD notes providing proof ideas for correction capability via triangle inequality and Hamming spheres. ↩
-
- 2Step 2
If codeword is sent and the received word is , then .
- 3Step 3
For successful correction, no other valid codeword can also lie within distance of .
- 4Step 4
If both and , then .
- 5Step 5
But distinct codewords must be separated by at least . Therefore ambiguity is impossible only when , equivalently .2
Footnotes
-
Codewords and Hamming Distance • Error Detection: parity - MIT - MIT notes summarizing how minimum distance determines detectable and correctable errors. ↩
-
Hamming Metric and the Minimum Distance - UCSD notes providing proof ideas for correction capability via triangle inequality and Hamming spheres. ↩
-
- 6Step 6
Correction is harder than detection because the decoder must identify the original word, not just flag inconsistency.
Common Questions and Edge Cases
For binary words and of equal length,
where counts the number of s in the XOR result.2
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩
-
Minimum Hamming Distance - GeeksforGeeks - Accessible explanation of Hamming weight, Hamming distance, and examples. ↩
Conceptual Roadmap for Learning Block Coding and Hamming Distance
Represent data in fixed-size blocks
Stage 1Divide the bit stream into -bit datawords so encoding can be applied systematically."
Footnotes
-
Data Link Layer - Data link layer notes explaining datawords, codewords, redundancy, and minimum-distance rules. ↩
Add redundancy
Stage 2Map each dataword to an -bit codeword with , introducing structure into the set of valid words."
Footnotes
-
Data Link Layer - Data link layer notes explaining datawords, codewords, redundancy, and minimum-distance rules. ↩
Measure pairwise separation
Stage 3Use Hamming distance to quantify how far apart codewords are in binary space.2"
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩
-
Minimum Hamming Distance - GeeksforGeeks - Accessible explanation of Hamming weight, Hamming distance, and examples. ↩
Find $d_{min}$
Stage 4Compute the smallest pairwise distance among all valid codewords; this determines guaranteed capability.2"
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩
-
Data Link Layer - Data link layer notes explaining datawords, codewords, redundancy, and minimum-distance rules. ↩
Apply detection and correction conditions
Stage 5Use for detection and for correction.3"
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩
-
Codewords and Hamming Distance • Error Detection: parity - MIT - MIT notes summarizing how minimum distance determines detectable and correctable errors. ↩
-
Hamming Metric and the Minimum Distance - UCSD notes providing proof ideas for correction capability via triangle inequality and Hamming spheres. ↩
Interpret geometrically
Stage 6View valid codewords as centers of Hamming spheres whose overlap properties determine correctability.2"
Footnotes
-
Introduction to binary block codes - MIT material on Hamming space, spheres, and geometric interpretation of block codes. ↩
-
Hamming Metric and the Minimum Distance - UCSD notes providing proof ideas for correction capability via triangle inequality and Hamming spheres. ↩
Frequent misconception
A code that can detect errors does not automatically correct error and detect errors simultaneously under all decoding strategies. For example, correcting error requires , but correcting and also safely distinguishing some larger patterns may need stronger constraints depending on the decoder and objective.
Footnotes
-
Codewords and Hamming Distance • Error Detection: parity - MIT - MIT notes summarizing how minimum distance determines detectable and correctable errors. ↩
Network-Theory Interpretation
Within the data link layer, block coding supports reliable frame delivery across imperfect physical media.2 Although many practical systems use specialized error-detecting codes such as CRC for frame checking, the theory of block coding and Hamming distance provides the mathematical foundation for understanding why redundancy works at all.2 The key ideas transfer broadly:
- legal patterns are separated in code space,
- channel noise perturbs transmitted patterns,
- receiver logic exploits structure to detect or correct perturbations.2
From a design perspective, block coding creates a tradeoff:
This is why coding theory sits naturally inside network performance analysis: it connects bandwidth, noise tolerance, and decoding certainty.
A concise summary is:
| Concept | Meaning | Key formula |
|---|---|---|
| Block coding | Map information bits to coded bits | |
| Hamming distance | Number of differing positions between two words | |
| Minimum distance | Worst-case separation among valid codewords | |
| Error detection | Know an error occurred | |
| Error correction | Recover original codeword |
For this module, you should be able to compute distances between binary sequences, determine from a codebook, and prove or apply the thresholds for detection and correction.3
Footnotes
-
Data Link Layer - Akshay Jain - Lecture notes covering block coding, Hamming distance, minimum distance, and detection/correction conditions. ↩ ↩2 ↩3
-
Data Link Layer - Data link layer notes explaining datawords, codewords, redundancy, and minimum-distance rules. ↩ ↩2 ↩3
-
Introduction to binary block codes - MIT material on Hamming space, spheres, and geometric interpretation of block codes. ↩
-
Codewords and Hamming Distance • Error Detection: parity - MIT - MIT notes summarizing how minimum distance determines detectable and correctable errors. ↩ ↩2 ↩3
Knowledge Check
In a block code, what does the notation mean?