1. Introduction
Error detection and correction are crucial to ensure reliable data transmission between devices. One of the most widely used error detection and correction methods is Hamming code. Richard Hamming developed it in 1950 at Bell Labs. In particular, it can detect and correct a singlebit error by adding redundant (or parity) bits to the original data.
A few use cases of Hamming code include:

 Computer memory systems: RAM and hard disk
 Communication networks: Bluetooth, ethernet, and wifi
 Digital signal processing: Satellite communications and digital audio broadcasting
In this tutorial, we’ll first study the basic terms of Hamming code, such as redundant bits, parity bits, and parity bit calculation. Next, we’ll provide an illustrative example of how to encode a data block using the Hamming code. Then, we’ll explore the various steps involved in error detection and correction. After that, we’ll discuss the advantages and limitations of the Hamming code. Finally, we’ll wrap up the tutorial with a brief summary of the topics covered.
2. Hamming Code Basics
In this section, we’ll discuss the fundamental terminologies of the Hamming code, including redundant bits, parity bits, and parity bit calculation.
2.1. Redundant Bits
The central idea of the Hamming code is based on redundancy. In general, the sender first divides the original data into fixedsized blocks. It then adds some extra redundant bits to each data block before transmitting the block to the receiver. Upon reception, the receiver uses these bits to detect transmission error, locate the corrupted bit, and correct it. We can calculate the required number of redundant bits using the equation:
In this equation, is the number of redundant bits, and is the number of data bits in a block.
2.2. Parity Bits
We add parity bits as redundant bits to an original data block for detecting and correcting errors during transmission. These bits ensure that each data block’s total count of is either even or odd. There are two types of parity bits:
Odd parity bit: We set a parity bit to when the count of in a bit sequence is even; otherwise, we configure it to .
Even parity bit: We fix a parity bit to if the count of in a given set of bits is odd; otherwise, we set it to .
2.3. Parity Bit Calculation
A Hamming code has number of bits, which is the sum of data bits and parity bits. We now discuss the stepbystep process to obtain the position and value of parity bits:
 At first, we compute the number of parity bits using and the total number of bits in the Hamming code using
 Next, we convert the bit positions from to into binary numbers, i.e.,
 Then, we label the bit positions corresponding to the power of as parity bits and the remaining positions as the data bits, e.g.,
 At last, we determine the value of each parity bit in the Hamming code iteratively. In each iteration, we determine the value of parity bit by counting the number of in the bit positions that have in the position from the least significant bit in their binary representations. Then, we set the parity bit to if the number of is odd, considering even parity; otherwise, we set it to
3. An Illustrative Example
Let’s break down the process of generating a Hamming code by looking at an example binary data block . This will help us understand how the Hamming code works and how it detects and corrects errors during data transmission. We’ll now apply each of the steps discussed in the previous section, one by one.
Step 1: The number of parity bits is since and . Therefore, the length of the Hamming code is , that is, .
Step 2: The binary conversion of the bit positions from to is .
Step 3: The parity bits are placed at the positions since they are power of . In contrast, the data bits are kept at the positions . The image below shows the labeling of parity and data bits:
4. Error Detection and Correction
Let’s first discuss how to detect if there is an error in the received code. To do so, we recalculate the values of parity bits and perform parity checks. In particular, we record a for a parity check if the assigned and observed parity bits do not match. Otherwise, we record a . The recorded values are then written from right to left to form the checking number. The code is errorfree if the checking number is zero. Otherwise, an error has occurred at the bit position corresponding to the checking number, given that there is only a singlebit error.
Let’s assume that the eleventh bit of the codeword generated in the previous section is changed from to during transmission. Then, the received code is:
Now, we recalculate the parity bits and record their values based on the assigned and observed parity bits. The images below show the recorded values for parity bits , , , and , respectively:
Let’s obtain the checking number by writing the recorded values from right to left, i.e., , which is equal to decimal number eleven. This signifies that the received code has an error at the eleventh bit. In order to correct it, we just have to toggle the eleventh bit and the corrected code is:
5. Advantages and Limitations
The key advantages and notable limitations of the Hamming code are:
6. Conclusion
This tutorial first provides a brief overview of the Hamming code and its use cases. It then explains the basic concepts of the Hamming code, such as redundant bits, parity bits, and parity bit calculation.
Next, it presents an illustrative example of encoding a data block using parity bits. Later, it discusses and demonstrates the steps involved in error detection and correction. In the end, it highlights the key advantages and limitations of the Hamming code.