How to calculate fragment offset

Fragment offset is an essential aspect of IP datagram fragmentation. In cases where a datagram size exceeds the Maximum Transmission Unit (MTU) of a network, it becomes necessary to break the data into smaller pieces known as fragments to ensure smooth transmission. This article will guide you through the process of calculating the fragment offset.
Understanding IP Datagram Fragmentation:
When IPv4 datagrams are larger than the network’s MTU, they are partitioned into smaller fragments for hassle-free transmission. Each fragment has its own IP header containing essential information, such as source and destination IP addresses, protocol, and identification number.
Fragment Offset Calculation:
The integral step involved in calculating the fragment offset is understanding that it is measured in units of 8 bytes. Moreover, with IPv4 using a 13-bit field for the offset value, it allows a maximum of 8192 fragments with offsets ranging from 0 to 8189 (the last offset is for identifying reassembly).
Here is a step-by-step guide to calculate the fragment offset:
1. Determine the size of data in each fragment:
To begin calculating fragment offset, make sure that each fragment is divisible by 8 bytes. Take note that the final fragment can have fewer bytes.
2. Assign an identification number to each fragment:
Every individual fragment will have an identification number assigned in ascending order which matches the original packet header.
3. Calculate unique offsets for each fragment:
To identify the order at which fragments should be reassembled, assign offsets starting from 0. For every new fragment, calculate the new offset by adding previous offset and its respective data size (in units of 8 bytes).
Example Calculation:
Suppose you have a datagram of size 2400 bytes that needs to be fragmented into fragments no larger than 800 bytes each.
– The first fragment will have an offset of 0 and will contain 800 bytes of data.
Fragment 1:
Offset: (0 * 8) = 0
Data size: 800 bytes
– The second fragment will have an offset of (800/8 =) 100, with another 800 bytes of data.
Fragment 2:
Offset: (100 * 8) = 800
Data size: 800 bytes
– The third fragment will have an offset of (1600/8 =) 200, and include the remaining data.
Fragment 3:
Offset: (200 * 8) = 1600
Data size: (2400 – [800+800]) = 800 bytes
Conclusion:
Fragment offset plays a vital role in the successful transmission and reassembly of IP datagrams. By understanding how to calculate the fragment offset, you can ensure that your data is properly communicated across networks with varying MTU sizes.