The Internet Protocol (IP) serves as the primary network-layer host-to-host routing and delivery system of the TCP/IP suite. This curriculum guide covers the structural format of IPv4 packets and the exact mechanics of datagram fragmentation when transitioning across heterogeneous network links with differing transfer capacities.
The Internet Protocol (IP) provides a best-effort, connectionless packet delivery system. This means that IP does not guarantee reliable delivery, error-free transit, or sequential arrival of packets; these higher-level guarantees are left to the transport layer (e.g., TCP).
Packets at the IP layer are formally called datagrams. An IP datagram is a variable-length packet made of a header and payload data. The standard header ranges from to bytes in length, with any space beyond the core 20 bytes utilized for protocol options.
+-----------------------------------------------------------+
| IP Datagram |
+-----------------------------+-----------------------------+
| Header (20-60 B) | Payload (Data) |
| - Controls, Routing, Flags | - Encapsulated segments |
+-----------------------------+-----------------------------+To understand how packets travel through an internetwork, we must analyze the fields contained within the standard IPv4 header. The protocol formats headers in -byte (-bit) blocks.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| HLEN | ToS/DS | Total Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identification |Flags| Fragment Offset |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Time-to-Live | Protocol | Header Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source IP Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Destination IP Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options (Variable, 0-40 B) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+0100 ().An IP datagram can travel through highly diverse networking links (such as Ethernet, Wi-Fi, Frame Relay, or ATM) on its route from source to destination. Each underlying physical network layer enforces its own limit on the maximum size of a frame payload. This limitation is known as the Maximum Transmission Unit (MTU).
[Host] ---> (Ethernet: MTU 1500) ---> [Router] ---> (WAN: MTU 576) ---> [Host]When a router receives a datagram that is larger than the outgoing network link's MTU, it must break the datagram down into smaller units. This process is called Fragmentation.
Three primary fields in the IP header orchestrate fragmentation and reassembly:
This 16-bit field guarantees that fragments of the same original datagram can be grouped together at the destination host. All fragments of a parent datagram will share the exact same Identification number.
A 3-bit field organized as follows:
A 13-bit field representing where this fragment's data belongs in the original payload. Because the offset field is only bits while the maximum payload size is bytes, the offset cannot represent single-byte increments. Instead, it measures distance in units of 8-byte blocks (often called eighth-byte units or octets).
Thus, the actual byte offset of a fragment is calculated as:
Because of this mapping, the payload data size of every intermediate fragment must be a multiple of 8 bytes.
Original Datagram:
+-----------------------------------------------------------+
| Header (20B) | Payload Data (0 to 3999) | (Total Length = 4020B)
+-----------------------------------------------------------+
Divided into 3 Fragments over an MTU of 1500 bytes:
Fragment 1:
+-----------------------+
| Header (20B) | Data 0 | (Bytes 0-1399) [Total Length = 1420, M = 1, Offset = 0]
+-----------------------+
Fragment 2:
+-----------------------+
| Header (20B) | Data 1 | (Bytes 1400-2799) [Total Length = 1420, M = 1, Offset = 175]
+-----------------------+
Fragment 3:
+-----------------------+
| Header (20B) | Data 2 | (Bytes 2800-3999) [Total Length = 1220, M = 0, Offset = 350]
+-----------------------+Note on Offset Calculations:
To programmatically simulate how a router handles the division of an IP payload given an arbitrary MTU constraint, we can utilize the following calculation script written in Python. This demonstrates the division of payloads into -byte aligned blocks.
def fragment_ip_packet(payload_size, header_size, mtu):
"""
Simulates IP datagram fragmentation over a specific link MTU.
"""
max_payload_per_fragment = mtu - header_size
# Must be a multiple of 8 bytes for intermediate fragments
aligned_payload_size = (max_payload_per_fragment // 8) * 8
if aligned_payload_size <= 0:
raise ValueError("MTU is too small to carry even a single 8-byte aligned payload.")
fragments = []
bytes_remaining = payload_size
current_byte = 0
while bytes_remaining > 0:
# Last fragment does not need to be a multiple of 8 bytes
if bytes_remaining <= max_payload_per_fragment:
This automated structure verifies that each sub-block is correctly aligned, ensuring that routers on subsequent network hops can continue to fragment packets down further if they encounter even narrower MTU paths down the line.
A variable-length unit of data consisting of a 20-to-60 byte header and a payload of up to 65,535 bytes.
The maximum frame payload size permitted by a physical link-layer protocol.
A 4-bit field representing the total size of the IP header in terms of 4-byte (32-bit) words.
A 3-bit field (comprising Reserved, Don't Fragment, and More Fragments flags) that controls and identifies packet division.
A 13-bit field indicating the exact relative position of fragmented payload data within the original unfragmented payload, measured in 8-byte blocks.
Test your understanding with 5 questions
An IP packet arrives with a Header Length (HLEN) value of 0110 in binary. How many bytes of options are carried by this packet?
If an IP fragment has a Fragment Offset value of 185, what is the sequence number of the first payload byte in this fragment?
A packet arrives at a destination host with the More Fragments (M) bit set to 0 and a Fragment Offset value of 350. What does this indicate?
An IP datagram has a total length of 1200 bytes and an HLEN of 5. What is the size of the payload (data) carried inside this datagram?
Why must the payload data size of all intermediate IP fragments be a multiple of 8 bytes?
6 Modules
6 Modules