G27
Self-checkedTier 1 9 min readcn.ipv4-fragmentation

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 (15001500 bytes for Ethernet, 576576 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 (2020 bytes without options; up to 6060 with options). Fields (quoted from the RFC / textbooks):

fieldbitsmeaning
version444
header length (IHL)4header length in 4-byte words, 55 to 1515 (so 2020 to 6060 bytes)
type of service8priority / differentiated services bits
total length16header plus data in bytes; at most 65 53565\,535
identification16the same in all fragments of one datagram
flags3reserved bit; DF (don't fragment); MF (more fragments)
fragment offset13position of this fragment's data in the original data, in units of 8 bytes
time to live (TTL)8decremented by every router; the packet is discarded at 00
protocol8upper layer: 66 TCP, 1717 UDP, 11 ICMP
header checksum16checksum of the header only (Internet checksum, error detection)
source address32
destination address32
options0 to 320rarely 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 88 bytes (13 bits are enough for offsets up to 65 52865\,528). The MF flag is 11 in every fragment except the last. A datagram that was not fragmented has offset 00 and MF =0= 0.

Because the offset counts 88-byte units, the data in every fragment except the last must be a multiple of 88 bytes.

How it works

Cutting a datagram

A router must forward a datagram of total length TT with header length hh on a link with MTU mm. If T≤mT \le m 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:

  1. each fragment gets a copy of the header, with new total length, offset and MF;
  2. the data per fragment is the largest multiple of 88 not exceeding m−hm - h:   c=8⌊(m−h)/8⌋\; c = 8 \lfloor (m - h)/8 \rfloor;
  3. the last fragment carries the rest.

The number of fragments is ⌈(T−h)/c⌉\lceil (T - h)/c \rceil.

A 4000-byte datagram over a link with MTU 1500: start

Computed by a script, not typed
fragmenttotal lengthdata bytesfragment offset fielddata byte rangeMF
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.

0 / 3
computed by script: fragments are cut and reassembled, routing tables are computed round by round, flooding is simulated. python3 scripts/gen-cn3-traces.py

A 40004000-byte datagram (header 2020, data 39803980) on a link with MTU 15001500: c=8⌊1480/8⌋=1480c = 8 \lfloor 1480/8 \rfloor = 1480 (14801480 is already a multiple of 88). Number of fragments ⌈3980/1480⌉=3\lceil 3980/1480 \rceil = 3: data 14801480, 14801480, 10201020; total lengths 15001500, 15001500, 10401040; offset fields 00, 1480/8=1851480/8 = 185, 2960/8=3702960/8 = 370; MF =1,1,0= 1, 1, 0.

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 11.

Fragments are fragmented again on a smaller MTU: start

Computed by a script, not typed
piececame fromtotal lengthdata bytesoffset fieldMF
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).

0 / 8
computed by script: fragments are cut and reassembled, routing tables are computed round by round, flooding is simulated. python3 scripts/gen-cn3-traces.py

When these fragments reach a link with MTU 576576 (c=552c = 552), the first two fragments each become three pieces (552,552,376552, 552, 376 data bytes) and the third becomes two (552552 and 468468): 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 linkfragmentsextra header bytesbytes 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)⌉.

0 / 7
computed by script: fragments are cut and reassembled, routing tables are computed round by round, flooding is simulated. python3 scripts/gen-cn3-traces.py

A 15011501-byte datagram on a 15001500-byte link is cut into two (the second carries a single byte of data and a 2020-byte header). A maximum-size datagram (65 53565\,535 bytes) on Ethernet needs 4545 fragments and 880880 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 00 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

Easy

A 24002400-byte datagram (header 2020) on a link with MTU 10001000: c=8⌊980/8⌋=8×122=976c = 8 \lfloor 980/8 \rfloor = 8 \times 122 = 976. Data 23802380: ⌈2380/976⌉=3\lceil 2380/976 \rceil = 3 fragments with data 976,976,428976, 976, 428 (total lengths 996,996,448996, 996, 448) and offset fields 0,122,2440, 122, 244.

EX 2The last fragment

Medium

The data field of the last fragment above has 428428 bytes, so its offset field is 244244 (=1952/8= 1952/8) and MF =0= 0. The destination checks that the first fragment has offset 00, the offsets and lengths join up, and the last one has MF =0= 0; then the original data length is 1952+428=23801952 + 428 = 2380 bytes.

EX 3Fragmenting twice

Medium

A 15001500-byte datagram goes through a link with MTU 576576 and then (still as fragments) through a link with MTU 296296. After the first link: 572,572,396572, 572, 396 bytes (data 552,552,376552, 552, 376). On the MTU-296296 link c=8⌊276/8⌋=272c = 8 \lfloor 276/8 \rfloor = 272: each 552552-byte data field becomes 272+272+8272 + 272 + 8, the 376376 becomes 272+104272 + 104. Total pieces: 3+3+2=83 + 3 + 2 = 8. 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 40004000-byte datagram on MTU 15001500?" 370370 (the offset field is data position 29602960 divided by 88). (b) "Which fragments have MF =1= 1?" All except the last. (c) "Where are fragments reassembled?" At the destination. (d) "What does a router do if DF =1= 1 and the packet is too big?" Discards it and sends an ICMP error. (e) "Maximum data per fragment on MTU 15001500 with a 2020-byte header?" 14801480. (f) "With MTU 10001000 and header 2020: data per fragment?" 976976 (the largest multiple of 88 not above 980980).

Cheat box

Cheat box

  • Header 2020 to 6060 bytes (IHL ×4\times 4); total length in bytes (16 bits); offset in units of 88 bytes (13 bits).
  • Data per fragment: c=8⌊(MTU−h)/8⌋c = 8 \lfloor (\text{MTU} - h)/8 \rfloor; fragments =⌈(T−h)/c⌉= \lceil (T - h)/c \rceil.
  • MF =1= 1 except in the last fragment; offset == (data bytes before the fragment) / 88, counted from the original data.
  • Same identification in all fragments; reassembly only at the destination.
  • DF =1= 1 and too big: drop and ICMP error. TTL decremented and checksum recomputed at every router.

Traps and GATE patterns

Connections

The MTU of Ethernet is the 15001500-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

GATE 2025 · MCQQ7 · page 548 of the book
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
GATE 2025 · NATQ9 · page 548 of the book
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 ________.
GATE 2024 · NATQ18 · page 550 of the book
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
______.
GATE 2024 · MSQQ19 · page 550 of the book
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.
GATE 2024 · MSQQ20 · page 550 of the book
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
GATE 2021 · MSQ · 2 marksQ32 · page 552 of the book
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
GATE 2020 · MSQ · 1 markQ36 · page 553 of the book
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
GATE 2018 · NAT · 2 marksQ42 · page 554 of the book
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 __________.
GATE 2017 · NATQ49 · page 555 of the book
The maximum number of IPv4 router addresses that
can be listed in the record route (RR) option field of
an IPv4 header is __________.
GATE 2016 · NATQ51 · page 556 of the book
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
______.
GATE 2015 · MCQQ54 · page 556 of the book
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
GATE 2015 · MCQQ57 · page 556 of the book
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
GATE 2014 · MCQQ63 · page 558 of the book
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
GATE 2014 · NATQ64 · page 558 of the book
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 __________.
GATE 2014 · MCQQ65 · page 558 of the book
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)
GATE 2013 · MCQ · 2 marksQ71 · page 559 of the book
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
GATE 2010 · MCQ · 1 markQ80 · page 561 of the book
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
GATE 2006 · MCQ · 1 markQ88 · page 562 of the book
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 30003000-byte datagram (header 2020) enters a link with MTU 10001000. Give the offsets and MF of the fragments.

Show answer

c=976c = 976; data 29802980: fragments with data 976,976,976,52976, 976, 976, 52; offsets 0,122,244,3660, 122, 244, 366; MF 1,1,1,01, 1, 1, 0; total lengths 996,996,996,72996, 996, 996, 72.

Question 2

Why must the data in a non-last fragment be a multiple of 88 bytes?

Show answer

The next fragment's offset is counted in units of 88 bytes, so it must start at a multiple of 88.

Question 3

If one fragment of a datagram is lost, what happens?

Show answer

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 c=8⌊(MTU−h)/8⌋c = 8\lfloor (\text{MTU} - h)/8 \rfloor; offset in 8-byte units; MF =1= 1 except last.
  • Same ID; reassembled at the destination only; lost fragment loses the datagram.
  • DF =1= 1: 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