IP Fragmentation
How large IP packets are divided and reassembled across different MTU sizes.
The Problem: Different Road Sizes on the Information Superhighway
Imagine the internet is a global logistics network. Your data travels in digital "trucks" called packets. A packet, like a truck, has a certain size, determined by how much "cargo" (data) it's carrying. Now, imagine this truck is driving from a warehouse in Texas (your computer) to a distribution center in New York (a web server). The journey isn't a single, uniform highway. Instead, it's a series of different roads, bridges, and tunnels, each with its own size limits. A wide Texas highway might allow very large trucks, but a historic tunnel in Pennsylvania might have a much lower height clearance.
In networking, this "vehicle size limit" for a particular physical network (like an Ethernet LAN, a Wi-Fi connection, or a long-distance fiber link) is called the Maximum Transmission Unit (MTU). The MTU defines the largest possible packet, in bytes, that can be transmitted over that specific link. The most common MTU you'll encounter is for Ethernet, which is 1500 bytes.
A problem arises when a large packet, created for a network with a high MTU, needs to travel through another network with a smaller MTU. Just like a truck that's too tall for a tunnel, the large packet simply cannot pass through. The solution is not to turn back; it's to break the large packet down into smaller pieces that will fit. This process is known as .
The IPv4 Fragmentation Toolkit: A Look Inside the Header
To manage the process of breaking down a packet and ensuring it can be correctly put back together at the destination, IPv4 uses a set of specific fields within its header. These fields act like a detailed instruction manual attached to each piece of the original packet.
As covered in the IPv4 Header topic, three specific fields work together as a team to handle fragmentation:
- Identification (16 bits): To identify which original packet a fragment belongs to.
- Flags (3 bits): To control the fragmentation process and mark the last fragment.
- Fragment Offset (13 bits): To specify the exact position of the fragment's data within the original packet.
A Deep Dive into the Fragmentation Control Fields
Let's examine each of these three fields in detail to understand their precise roles in the fragmentation and reassembly process.
Identification (ID) Field
Analogy: Think of this as a unique shipment tracking number. If you disassemble a large piece of furniture for shipping, you write the same shipment number (e.g., "Shipment #12345") on every single box. When the boxes arrive, even if they arrive separately, the recipient can easily see they all belong to the same piece of furniture.
In networking, when a router fragments an IP datagram, it copies the Identification value from the original datagram into the header of every single fragment. The destination host will then use this common ID to group together all the received fragments that belong to the same original packet before it can begin reassembly. This 16-bit field allows for unique identifiers before the numbers need to be reused.
Flags Field
This 3-bit field acts as a set of on/off switches that provide critical control signals.
- Bit 0: Reserved. This bit is always set to 0.
- Bit 1: Don't Fragment (DF) Flag. When this bit is set to 1, it is a strict command to routers: "You are forbidden to fragment this packet." If a router receives a packet with the DF flag set, and the packet is larger than the MTU of the next link, the router has no choice but to discard the packet. It will then typically send an ICMP "Fragmentation Needed and DF set" error message back to the original sender.
Analogy: This is the equivalent of putting a large "FRAGILE - DO NOT BEND" sticker on an envelope. The postal service can't fold it to fit in a smaller mailbox; they must return it. This flag is the cornerstone of a very important mechanism called . - Bit 2: More Fragments (MF) Flag. This flag is essential for reassembly. It tells the destination host whether more fragments are on the way.
- If the MF flag is set to 1, it means "This is a fragment of a larger packet, and there are more fragments coming after this one."
- If the MF flag is set to 0, it means one of two things: either this is the last fragment of a packet, or the packet was never fragmented at all. The destination knows it has received the final piece when it gets a fragment with MF=0.
Fragment Offset Field
Analogy: This is like the assembly instructions that tell you how the parts of the disassembled furniture fit together. The label on each box might say "This box contains the parts from 0cm to 100cm" or "This box contains the parts from 100cm to 200cm".
The Fragment Offset field tells the destination host exactly where in the original datagram's data payload the data in this particular fragment belongs. This allows the host to reassemble the data in the correct order, even if the fragments arrive out of sequence.
The 8-Byte Rule
There's a critical technical detail: the offset is not measured in single bytes. It is measured in 8-byte units. The value in the Fragment Offset field must be multiplied by 8 to get the actual byte offset.
Why? The field is only 13 bits long, which allows for distinct values. If each value represented one byte, we could only describe an offset up to 8192 bytes. However, the maximum size of an IPv4 packet's payload is nearly 64 KB (65515 bytes). By making each unit of offset equal to 8 bytes, the 13-bit field can cover the entire possible range: bytes.
This means that, with the exception of the final fragment, the data payload of every fragment must be a multiple of 8 bytes.
In-Depth Example: A 4000-Byte Packet Meets a 1500-Byte MTU
Let's walk through the entire process. A source host sends a large IP datagram, which a router needs to fragment.
- Original Datagram Size: 4000 bytes
- Header Size: 20 bytes
- Payload (Data) Size: bytes
- Network MTU: 1500 bytes
Step 1: Calculate Fragment Size
A router receives the 4000-byte packet. The next link has an MTU of 1500 bytes. This means the total size of each fragment (header + data) cannot exceed 1500 bytes.
Maximum data per fragment = MTU - Header Size = bytes.
We must also adhere to the 8-byte rule for the offset. Is 1480 divisible by 8? Yes, . So, we can use the maximum possible data size of 1480 bytes for our fragments.
Step 2: Create the First Fragment
The router creates the first fragment containing the first part of the original data.
- Data: The first 1480 bytes of the original 3980-byte payload (Bytes 0-1479).
- Total Length: bytes.
- Identification: Copied from the original packet (let's say it's 1234).
- Flags: DF is 0. Since there is more data to come, MF is set to 1.
- Fragment Offset: This fragment starts at byte 0 of the original payload. The offset value is .
Step 3: Create the Second Fragment
We still have bytes of data left to send. The router creates the second fragment.
- Data: The next 1480 bytes of the original payload (Bytes 1480-2959).
- Total Length: bytes.
- Identification: 1234 (must be the same).
- Flags: DF is 0. There is still more data to come, so MF is still 1.
- Fragment Offset: This fragment's data starts at byte 1480 of the original payload. The offset value is .
Step 4: Create the Final Fragment
We now have bytes of data remaining. The router creates the third and final fragment.
- Data: The last 1020 bytes of the original payload (Bytes 2960-3979).
- Total Length: bytes.
- Identification: 1234 (must be the same).
- Flags: DF is 0. This is the last piece of the original packet, so MF is set to 0. This signals the end to the receiver.
- Fragment Offset: This fragment's data starts at byte 2960 of the original payload. The offset value is .
The original 4000-byte packet has now been successfully converted into three smaller fragments (1500, 1500, and 1040 bytes), each with a correctly configured header, ready to be sent across the network. The destination host will use the identical ID, the increasing offsets, and the final MF=0 flag to perfectly reassemble the original data.
The IPv6 Approach: End-to-End Responsibility
The designers of IPv6 recognized that fragmentation by intermediate routers was a major source of inefficiency. In the IPv6 model:
- Routers DO NOT Fragment: Intermediate routers in an IPv6 network are forbidden from fragmenting packets.
- Path MTU Discovery (PMTUD): It is the responsibility of the source host to determine the smallest MTU along the entire path to the destination. It does this by sending packets and listening for "Packet Too Big" error messages from any router that cannot forward them. The host then sizes its packets appropriately before sending.
- Fragmentation Extension Header: If a source host absolutely must send a packet larger than the Path MTU, it can perform fragmentation itself and include a special Fragmentation Extension Header. This header contains the same type of information as the IPv4 fields (ID, flags, offset). Critically, this header is only processed by the final destination host, not by the routers in between, keeping the core network fast.
The Drawbacks and Issues with Fragmentation
Although necessary for IPv4, fragmentation is generally considered a harmful process that should be avoided whenever possible due to several significant drawbacks.
- Performance Overhead: Fragmentation increases the workload for both the router that performs the fragmentation (it must create multiple new headers) and the destination host that must reassemble the pieces, consuming CPU and memory.
- Increased Unreliability: The loss of a single fragment is catastrophic for the entire packet. If even one small piece of the original datagram is dropped in transit, the destination host cannot reassemble the whole thing. It must wait for a timeout and then discard all the other fragments it has already received. The entire original packet must then be retransmitted by the source, which significantly increases delay and wastes bandwidth.
- Security Vulnerabilities: Packet fragmentation has been exploited in various network attacks. For example, firewalls and intrusion detection systems can have difficulty inspecting fragmented traffic, as the complete data context is spread across multiple packets.
- Complications with NAT/Firewalls: Many firewalls and NAT devices operate based on port numbers found in the transport layer (TCP/UDP) header. However, in a fragmented IPv4 packet, only the first fragment contains this header. Subsequent fragments do not. This makes it difficult or impossible for the device to correctly filter or translate these subsequent fragments, often causing it to block them.