IPv4 header and fragmentation
The IPv4 header fields (version, header length, total length, identification, flags DF and MF, fragment offset, TTL, protocol, header checksum, addresses), why a datagram larger than the MTU of a link is fragmented, how the offset (in 8-byte units) and the MF flag are set, fragmentation of fragments on smaller MTUs, reassembly only at the destination, the cost of fragmentation, the number of fragments formula and the effect of the DF flag; fragmentation was checked at byte level with random packets and MTU paths.
Why it exists
Each link has a maximum transmission unit (MTU), the largest packet its frame can carry ( bytes for Ethernet, and other values for some links). A datagram built for a large-MTU link may meet a link with a smaller MTU on its way. IP's answer is fragmentation: the router cuts the datagram into pieces small enough for the next link, and the destination puts the pieces together again. GATE asks for the header fields, the number of fragments and the offset and flag values of each fragment.
Prerequisites
You need IP addresses (IPv4 addressing) and the idea of a link layer with a size limit (Ethernet).
Precise definitions
The IPv4 header ( bytes without options; up to with options). Fields (quoted from the RFC / textbooks):
| field | bits | meaning |
|---|---|---|
| version | 4 | |
| header length (IHL) | 4 | header length in 4-byte words, to (so to bytes) |
| type of service | 8 | priority / differentiated services bits |
| total length | 16 | header plus data in bytes; at most |
| identification | 16 | the same in all fragments of one datagram |
| flags | 3 | reserved bit; DF (don't fragment); MF (more fragments) |
| fragment offset | 13 | position of this fragment's data in the original data, in units of 8 bytes |
| time to live (TTL) | 8 | decremented by every router; the packet is discarded at |
| protocol | 8 | upper layer: TCP, UDP, ICMP |
| header checksum | 16 | checksum of the header only (Internet checksum, error detection) |
| source address | 32 | |
| destination address | 32 | |
| options | 0 to 320 | rarely used |
A fragment is itself an IP datagram with its own header. All fragments of a datagram have the same identification, source, destination and protocol. The fragment offset of a fragment says where its data start in the data of the original datagram, counted in units of bytes (13 bits are enough for offsets up to ). The MF flag is in every fragment except the last. A datagram that was not fragmented has offset and MF .
Because the offset counts -byte units, the data in every fragment except the last must be a multiple of bytes.
How it works
Cutting a datagram
A router must forward a datagram of total length with header length on a link with MTU . If it sends it as it is. If the DF flag is set it cannot fragment: it drops the datagram and sends an ICMP error ("fragmentation needed") back to the sender (which lets the sender learn the path MTU). Otherwise it cuts:
- each fragment gets a copy of the header, with new total length, offset and MF;
- the data per fragment is the largest multiple of not exceeding : ;
- the last fragment carries the rest.
The number of fragments is .
A 4000-byte datagram over a link with MTU 1500: start
Computed by a script, not typed| fragment | total length | data bytes | fragment offset field | data byte range | MF |
|---|---|---|---|---|---|
| fragment 1 | |||||
| fragment 2 | |||||
| fragment 3 |
Step 0
Datagram: header 20 bytes, data 3980 bytes. Each fragment may carry at most MTU - 20 = 1480 bytes, which is a multiple of 8 (the offset field counts 8-byte units), so 1480 bytes per fragment: ⌈3980/1480⌉ = 3 fragments.
A -byte datagram (header , data ) on a link with MTU : ( is already a multiple of ). Number of fragments : data , , ; total lengths , , ; offset fields , , ; MF .
Fragments of fragments
A fragment can meet a link with an even smaller MTU and is fragmented again. The offset of a piece is always counted from the start of the original data, and the MF flag of the last piece of a non-last fragment stays .
Fragments are fragmented again on a smaller MTU: start
Computed by a script, not typed| piece | came from | total length | data bytes | offset field | MF |
|---|---|---|---|---|---|
| piece 1 | |||||
| piece 2 | |||||
| piece 3 | |||||
| piece 4 | |||||
| piece 5 | |||||
| piece 6 | |||||
| piece 7 | |||||
| piece 8 |
Step 0
The three fragments of the previous table reach a link with MTU 576. Reassembly is done only at the destination, which sorts the 8 pieces by offset and checks that they cover the data without gaps: it obtains the original 4000 bytes (checked).
When these fragments reach a link with MTU (), the first two fragments each become three pieces ( data bytes) and the third becomes two ( and ): eight pieces in all. Fragments are never reassembled by routers: only the destination reassembles, using the identification, the offsets and the MF flag. If any fragment is lost, the whole datagram cannot be reassembled and is discarded after a timeout; IP does not retransmit (TCP or the application must).
What fragmentation costs
Every fragment after the first adds a header, and the loss of one fragment loses the whole datagram:
How many fragments: start
Computed by a script, not typed| datagram and link | fragments | extra header bytes | bytes sent in total |
|---|---|---|---|
| 1500 bytes, MTU 1500 | |||
| 1501 bytes, MTU 1500 | |||
| 4000 bytes, MTU 1500 | |||
| 4000 bytes, MTU 576 | |||
| 65535 bytes, MTU 1500 | |||
| 1500 bytes, MTU 576 | |||
| 1500 bytes, MTU 296 |
Step 0
Number of fragments = ⌈(total length - header) / (⌊(MTU - header)/8⌋ × 8)⌉.
A -byte datagram on a -byte link is cut into two (the second carries a single byte of data and a -byte header). A maximum-size datagram ( bytes) on Ethernet needs fragments and additional bytes. For these reasons TCP chooses a segment size that avoids fragmentation (the maximum segment size, TCP).
Other header fields in routing
A router decrements TTL and recomputes the header checksum (the checksum covers the changed byte) for every datagram; when TTL reaches the datagram is discarded and an ICMP "time exceeded" is sent back (this is how traceroute works, quoted). The destination address is used for the forwarding decision (CIDR).
Worked examples
EX 1Number of fragments
EasyA -byte datagram (header ) on a link with MTU : . Data : fragments with data (total lengths ) and offset fields .
EX 2The last fragment
MediumThe data field of the last fragment above has bytes, so its offset field is () and MF . The destination checks that the first fragment has offset , the offsets and lengths join up, and the last one has MF ; then the original data length is bytes.
EX 3Fragmenting twice
MediumA -byte datagram goes through a link with MTU and then (still as fragments) through a link with MTU . After the first link: bytes (data ). On the MTU- link : each -byte data field becomes , the becomes . Total pieces: . Offsets continue to be counted from the beginning of the original data.
EX 4Typical questions
GATE level(a) "Fragment offset of the third fragment of a -byte datagram on MTU ?" (the offset field is data position divided by ). (b) "Which fragments have MF ?" All except the last. (c) "Where are fragments reassembled?" At the destination. (d) "What does a router do if DF and the packet is too big?" Discards it and sends an ICMP error. (e) "Maximum data per fragment on MTU with a -byte header?" . (f) "With MTU and header : data per fragment?" (the largest multiple of not above ).
Cheat box
Cheat box
- Header to bytes (IHL ); total length in bytes (16 bits); offset in units of bytes (13 bits).
- Data per fragment: ; fragments .
- MF except in the last fragment; offset (data bytes before the fragment) / , counted from the original data.
- Same identification in all fragments; reassembly only at the destination.
- DF and too big: drop and ICMP error. TTL decremented and checksum recomputed at every router.
Traps and GATE patterns
Connections
Across subjects
No cross-subject links yet.
The MTU of Ethernet is the -byte data field (Ethernet). TCP avoids IP fragmentation by limiting the segment size (TCP). The header checksum is the Internet checksum of the error detection page (error detection). Routers choose the output link by the destination address (CIDR).
PYQs
18 previous year questions from your book. I re-solved each one myself (11 by running or simulating, 7 by reasoning only); the book's key is shown next to my answer. All PYQs
Consider a network that uses Ethernet and IPv4. Assume that IPv4 headers do not use any options field. Each Ethernet frame can carry a maximum of 1500 bytes in its data field. A UDP segment is transmitted. The payload (data) in the UDP segment is 7488 bytes. Which ONE of the following choices has the CORRECT total number of fragments transmitted and the size of the last fragment including IPv4 header?
- (a)5 fragments, 1488 bytes
- (b)6 fragments, 88 bytes
- (c)6 fragments, 108 bytes
- (d)6 fragments, 116 bytes
Suppose a message of size 15000 bytes is transmitted from a source to a destination using IPv4 protocol via two routers as shown in the figure. Each router has a defined maximum transmission unit (MTU) as shown in the figure, including the IP header. The number of fragments that will be delivered to the destination is ________.
Consider sending an IP datagram of size 1420 bytes (including 20 bytes of IP header) from a sender to a receiver over a path of two links with a router between them. The first link (sender to router) has an MTU (Maximum Transmission Unit) size of 542 bytes, while the second link (router to receiver) has an MTU size of 360 bytes. The number of fragments that would be delivered at the receiver is ______.
Which of the following statements about IPv4 fragmentation is/are TRUE?
- (a)The fragmentation of an IP datagram is performed only at the source of the datagram.
- (b)The reassembly of fragments is performed at all intermediate routers along the path from the source to the destination.
- (c)The reassembly of fragments is performed only at the destination of the datagram.
- (d)The fragmentation of an IP datagram is performed at any IP router which finds that the size of the datagram to be transmitted exceeds the MTU.
Which of the following fields of an IP header is/are always modified by any router before it forwards the IP packet?
- (a)Time to Live (TTL)
- (b)Header Checksum
- (c)Protocol
- (d)Source IP Address
Consider two hosts P and Q connected through a router R. The maximum transfer unit (MTU) value of the link between P and R is 1500 bytes, and between R and Q is 820 bytes. A TCP segment of size 1400 bytes was transferred from P to Q through R, with IP identification value as 0x1234. Assume that the IP header size is 20 bytes. Further, the packet is allowed to be fragmented, i.e., Don't Fragment (DF) flag in the IP header is not set by P. Which of the following statements is/are correct?
- (a)Two fragments are created at R and the IP datagram size carrying the second fragment is 620 bytes.
- (b)If the second fragment is lost, P is required to resend the whole TCP segment.
- (c)TCP destination port can be determined by analyzing only the second fragment.
- (d)If the second fragment is lost, R will resend the fragment with the IP identification value 0x1234. COMPUTER NETWORK
Consider the following statements about the functionality of an IP-based router. I. A router does not modify the IP packets during forwarding. II. It is not necessary for a router to implement any routing protocol. III. A router should reassemble IP fragments if the MTU of the outgoing link is larger than the size of the incoming IP packet. Which of the above statements is/are TRUE?
- (a)I only
- (b)I and II only
- (c)II and III only
- (d)II only
Consider an IP packet with a length of 4500 bytes that includes a 20-byte IPv4 header and a 40-byte TCP header. The packet is forwarded to an IPv4 router that supports a Maximum Transmission Unit (MTU) of 600 bytes. Assume that the length of the IP header in all the outgoing fragments of this packet is 20 bytes. Assume that the fragmentation offset value stored in the first fragment is 0. The fragmentation offset value stored in the third fragment is __________.
The maximum number of IPv4 router addresses that can be listed in the record route (RR) option field of an IPv4 header is __________.
An IP datagram of size 1000 bytes arrives at a router. The router has to forward this packet on a link whose MTU (maximum transmission unit) is 100 bytes. Assume that the size of the IP header is 20 bytes. The number of fragments that the IP datagram will be divided into for transmission is ______.
Host A sends a UDP datagram containing 8880 bytes of user data to host B over an Ethernet LAN. Ethernet frames may carry data up to 1500 bytes (i.e., MTU = 1500 bytes). Size of UDP header is 8 bytes and size of IP header is 20 bytes. There is no option field in the IP header. How many total number of IP fragments will be transmitted and what will be the contents of the offset field in the last fragment?
- (a)6 and 925
- (b)6 and 7400
- (c)7 and 1110
- (d)7 and 8880
Which one of the following fields of an IP header is NOT modified by a typical IP router?
- (a)Checksum
- (b)Source address
- (c)Time to Live(TTL)
- (d)Length
An IP router with a Maximum Transmission Unit (MTU) of 1500 bytes has received an IP packet of size 4404 bytes with an IP header of length 20 bytes. The values of the relevant fields in the header of the third IP fragment generated by the router for this packet are:
- (a)MF bit: 0, Datagram Length: 1444; Offset: 370
- (b)MF bit: 1, Datagram Length: 1424; Offset: 185
- (c)MF bit: 1, Datagram Length: 1500; Offset: 370
- (d)MF bit: 0, Datagram Length: 1424; Offset: 2960
In the diagram shown below, L1 is an Ethernet LAN and L2 is a Token-Ring LAN. An IP packet originates from sender S and traverses to R, as shown. The links within each ISP and across the two ISPs, are all point-to-point optical links. The initial value of the TTL field is 32. The maximum possible value of the TTL field when R receives the datagram is __________.
Host A (on TCP/IP v4 network A) sends an IP datagram D to host B (also on TCP/IP v4 network B). Assume that no error occurred during the transmission of D. When D reaches B, which of the following IP header field(s) may be different from that of the original datagram D? (i) TTL (ii) Checksum (iii) Fragment Offset
- (a)(i) only
- (b)(i) and (ii) only
- (c)(ii) and (iii) only
- (d)(i),(ii) and (iii)
In an IPv4 datagram, the M bit is 0, the value of HLEN is 10, the value of total length is 400 and the fragment offset value is 300. The position of the first fragment in the datagram, the sequence numbers of the payload, and the last bytes of the payload, respectively, are
- (a)Last fragment, 2400 and 2789
- (b)First fragment, 2400 and 2759
- (c)Last fragment, 2400 and 2759
- (d)Middle fragment, 300 and 689
One of the header fields in an IP datagram is the Time-to-Live (TTL) field. Which of the following statements best explains the need for this field?
- (a)It can be used to prioritize packets
- (b)It can be used to reduce delays
- (c)It can be used to optimize throughput
- (d)It can be used to prevent packet looping
For which one of the following reasons does Internet Protocol (IP) use the time-to-live (TTL) field in the IP datagram header?
- (a)Ensure packets reach destination within that time
- (b)Discard packets that reach later than that time
- (c)Prevent packets from looping indefinitely
- (d)Limit the time for which a packet gets queued in intermediate routers
Self-check
Question 1
A -byte datagram (header ) enters a link with MTU . Give the offsets and MF of the fragments.
Show answerHide
; data : fragments with data ; offsets ; MF ; total lengths .
Question 2
Why must the data in a non-last fragment be a multiple of bytes?
Show answerHide
The next fragment's offset is counted in units of bytes, so it must start at a multiple of .
Question 3
If one fragment of a datagram is lost, what happens?
Show answerHide
The destination cannot reassemble the datagram; after a timeout it discards the received fragments. IP does not retransmit.
Revision card
One-screen revision
- Fragment data ; offset in 8-byte units; MF except last.
- Same ID; reassembled at the destination only; lost fragment loses the datagram.
- DF : drop and ICMP. TTL decrement and checksum at each hop.
References
- ·Kurose, Ross, Computer Networking: A Top-Down Approach (8th edition), Chapter 4, Section 4.3.1 (IPv4 datagram format)
- ·Tanenbaum, Wetherall, Computer Networks (5th edition), Chapter 5, Section 5.6.1 (The IP version 4 protocol)
- ·Forouzan, Data Communications and Networking (5th edition), Chapter 19, Section 19.1 (Internetworking: fragmentation)
Verification
scripts/enum-checks/cn_route_check.py: 3000 random payloads (1 to 3000 bytes) with header sizes 20, 24, 40 and 60, cut and rebuilt byte for byte, also over up to four decreasing MTUs (fragments of fragments, offsets counted from the start of the original data): the pieces rebuild the payload, all offsets are multiples of 8 bytes, all pieces except the last carry a multiple of 8 data bytes, MF is 1 on every piece except the last, every piece fits the MTU; the fragment() function equals the independent byte-level cutter; the number of fragments equals ceil(data / (floor((MTU - header)/8) x 8)) and is the MINIMUM possible (exhaustive search over all ways to cut small payloads); a missing fragment prevents reassembly; the header checksum property (sum of all ten words including the checksum is all ones) and its recomputation after changing the TTL byte. QUOTED, not computable here: the header field list and sizes (version 4 bits, IHL 4 bits, type of service 8, total length 16, identification 16, flags 3, offset 13, TTL 8, protocol 8, checksum 16, source 32, destination 32, options up to 40 bytes), the protocol numbers (6 TCP, 17 UDP, 1 ICMP), the default TTL values and the behaviour of the DF flag with path MTU discovery (ICMP 'fragmentation needed'). IPv6 (no fragmentation by routers) is outside the syllabus line and is only mentioned. Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (CRC remainders, binomial tail, checksums); long C programs were not re-read line by line (they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose). No defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)