How do IP fragmentation and reassembly work?
Data is transported through a network using IP packets, each of which consists of a header and a data segment. There are two versions of IP packets: IPV4 and IPV6. In this Answer, we will look at IPV4.
The IPV4 packet has a maximum size of
The minimum header size is
Keeping this in mind, the maximum data that can be sent in a packet is
Why is fragmentation needed?
IPV4 can be used in many data link layers, each having its own maximum frame size or Maximum Transmission Unit (MTU). The MTU is the largest packet a data link layer can send, including its header. The MTU values of some commonly used data link layers are shown below.
Data link layer | MTU |
Ethernet | 1,500 bytes |
IEEE 802.11 WiFi | 2,304 bytes |
Token Ring (802.15.4) | 4,464 bytes |
FDDI | 4,352 bytes |
As we can see in the table above, all of the MTU values are significantly smaller than the maximum size of an IPV4 packet. Therefore, to pass data safely through the network, the large IPV4 packet is fragmented into two or more IPV4 packets.
Fragmentation
Fragmentation is the breaking of an IPV4 packet that exceeds the MTU of the data link layer into smaller IPV4 packets. Fragmentation is a process performed by the sender or the forwarding routers.
Fragmentation relies on some of the fields in the IPV4 header, which are as follows:
Identification: To identify fragments, we use a 16-bit field.
When the packet is fragmented, the identification field is copied into the fragmented packet headers to help determine that the packet belongs to a specific frame.Fragment offset: This is a 13-bit field that is used to order the data into fragments; it helps in the rearranging part. As discussed above, the largest data offset can be
, but we need bits to represent this number. The solution is to scale down by introducing a scaling factor. As we can see below, the scaling factor is equal to . This means all the fragments except the last one should have data in multiples of .
MF (More fragments): It is a one-bit flag that specifies if there are more fragments of the frame. All the fragmented packets have this flag set to
except the last packet which sets this flag to . This flag along with the fragment offset helps the receiver identify the order during reassembly. DF (Don't fragment): It is a one-bit flag that tells the routers whether to fragment the packet or not. If it is set to
then the packet can be fragmented.
Reassembly
The reassembly process is carried out at the destination. This is because packets take different routes through the network and arrive at different times.
The steps of the process of reassembly are as follows:
The destination identifies that the packet has been fragmented using the MF and fragment offset fields.
The destination categorizes the incoming packets according to their identification fields. Two packets with the same identification field are put in the same category.
The packets within a category are sequenced using the MF and fragment offset. First, the packets with MF equal to
are sorted in ascending order based on their fragment offset values. Then the packet having an MF equal to and a fragment offset not equal to 0 is placed at the end, since it's the last packet.
Example
Consider an example where a packet with a size of
Test yourself
Given the sample MTU size of 100 and an IP packet of size 999, how many fragments will be created?
11
12
13
Free Resources