Sub topic 7
MTU and Why IPv4 Fragments Packets
Prerequisites and the MTU
This chapter assumes that you understand IPv4 addresses, binary arithmetic, packets, routers, and basic network layers.
A maximum transmission unit, or MTU, is the largest IP packet that a link can carry in one frame. Ethernet commonly uses an MTU of 1500 bytes. The MTU includes the IPv4 header and the packet data.
If a router must send an IPv4 packet through a link whose MTU is smaller than the packet, IPv4 can split the packet into fragments. Each fragment travels as a separate packet. The destination later reassembles the fragments into the original datagram.
Fields Used for Fragmentation
The IPv4 header contains fields that allow the destination to identify and order fragments.
| Field | Purpose |
|---|---|
| Identification | Same value for all fragments of one original datagram |
| DF flag | Do not fragment; a router must reject an oversized packet |
| MF flag | More fragments follow |
| Fragment offset | Position of this fragment's data, in units of 8 bytes |
| Total length | Header plus data length of this fragment |
Every fragment receives its own IPv4 header. Therefore, the fragment data size is smaller than the MTU by the header size. Except for the final fragment, the data portion must be a multiple of 8 bytes because the offset uses 8-byte units.
Fragment Arithmetic
Suppose a 4000-byte datagram, including a 20-byte header, crosses a link with an MTU of 1500 bytes.
The largest data portion is:
1500 − 20 = 1480 bytes
The original datagram has 3980 bytes of data. The fragments are:
| Fragment | Total length | Data bytes | Offset | MF |
|---|---|---|---|---|
| 1 | 1500 | 1480 | 0 | 1 |
| 2 | 1500 | 1480 | 185 | 1 |
| 3 | 1040 | 1020 | 370 | 0 |
The second fragment's offset is 1480 divided by 8, which equals 185. The third begins after 2960 data bytes, so its offset is 2960 divided by 8, which equals 370. MF is 0 only on the final fragment.
def fragment(total_length, mtu, header=20):
data_left = total_length - header
data_per_fragment = (mtu - header) // 8 * 8
offset_bytes = 0
result = []
while data_left:
data_size = min(data_per_fragment, data_left)
data_left -= data_size
result.append((
header + data_size,
offset_bytes // 8,
int(data_left > 0)
))
offset_bytes += data_size
return result
print(fragment(4000, 1500))Path MTU and Loss
A router fragments only when the DF flag is clear. If DF is set, the router discards an oversized packet and normally sends an ICMP fragmentation-needed message to the sender. Path MTU discovery uses this feedback to reduce packet size.
The destination performs reassembly. If even one fragment is lost, the complete datagram cannot be reconstructed, so the remaining fragments are usually discarded after a timeout.
Exercise
A 3000-byte IPv4 datagram has a 20-byte header and crosses an MTU-1000 link. What are the total lengths and offsets of its fragments?
Show answer
Each fragment carries at most 976 data bytes, because 980 is reduced to the nearest multiple of 8. The fragments are (996, 0), (996, 122), (996, 244), and (60, 366), where each pair is total length and offset.