IPv4 subnetting, forwarding and fragmentation
Scope and prerequisites
Read an IPv4 header, calculate subnet boundaries, apply longest-prefix matching and fragment a datagram. Binary powers, byte/bit conversion and the distinction between an IP packet and link frame are prerequisites. Unless stated otherwise, examples use ordinary unicast subnets with network and directed-broadcast addresses reserved, a20-byte IPv4 header without options, and no tunneling.
1. Address and header meaning
IPv4 addresses contain32 bits. A /p prefix fixes the first p bits, leaving32−p host bits. The mask has p leading ones. Network address = address AND mask. Last address = network address with all host bits set. The block contains2^(32−p) addresses. For conventional subnets with at least two host bits, usable host addresses number2^(32−p)−2. Do not apply this subtraction blindly: /31 point-to-point links have special usage and /32 identifies a single address/host route.
The IPv4 header includes version, IHL, total length, identification, flags, fragment offset, TTL, protocol, header checksum and source/destination addresses. IHL counts32-bit words, so IHL5 means20 bytes and IHL6 means24. Total length includes header and payload. Protocol demultiplexes the payload, for example TCP6, UDP17 or ICMP1. The header checksum covers the IPv4 header only, not its data. A forwarding router decrements TTL and updates the header checksum; exhausted TTL leads to discarding, normally with the applicable ICMP error subject to its rules.
2. Subnet calculation and allocation
Worked example: 192.0.2.173/27 has mask255.255.255.224. Blocks advance by32 in the final octet.173 belongs to160…191, so network192.0.2.160, broadcast192.0.2.191 and ordinary hosts161…190, giving30 usable addresses. Check with AND:173 AND224=160. The address .173 itself is not the network boundary.
For a requirement of50 ordinary hosts, choose h with2^h−2≥50: h=6, so /26 and64 total addresses. VLSM assigns different prefix lengths to different requirements. Allocate largest blocks first and align every block to its size; a /26 cannot start arbitrarily at last octet16. Inside198.51.100.0/24, one valid allocation is .0/26 for50 hosts, .64/27 for25, and .96/28 for10. These consume64+32+16=112 addresses without overlap. A smaller prefix length means a larger address block.
3. CIDR aggregation and forwarding
A route prefix describes a contiguous, aligned power-of-two address block. Adjacent ranges are not automatically aggregatable.192.0.2.0/25 and192.0.2.128/25 combine exactly to192.0.2.0/24. By contrast, two adjacent /24s ending in third octets1 and2 cannot be represented exactly by one /23: a /23 starts on an even third octet. A summary broader than the owned/reachable set can attract traffic that cannot be delivered; route design must account for that.
Forwarding uses longest-prefix match among matching entries, not table order and not the smallest metric across unrelated prefix lengths. Example table:0.0.0.0/0→R0;10.0.0.0/8→R1;10.2.0.0/16→R2;10.2.3.0/24→R3. Destination10.2.3.99 uses R3;10.2.8.9 uses R2;10.9.1.1 uses R1;203.0.113.7 uses R0. Metrics and protocol preferences can determine which candidate route is installed for the same prefix; longest-prefix selection is a separate forwarding step.
4. IPv4 fragmentation
An outgoing link MTU limits the complete IP packet size on that link. If a packet exceeds it and DF is clear, IPv4 fragmentation may occur. With DF set, the router cannot fragment; it drops the oversized packet and normally sends the appropriate ICMP fragmentation-needed error. Path MTU discovery uses such feedback, with practical limitations when messages are filtered.
Each fragment has its own IP header and a portion of the original payload. Identification associates fragments of a datagram alongside source, destination and protocol. Fragment offset is measured in8-byte units relative to the original payload, not relative to the current parent fragment and not including any header. All nonfinal payload portions must be multiples of8 bytes. MF=1 means more original data follows; MF=0 marks the final fragment. Reassembly occurs at the destination, not at every intermediate router. Missing fragments prevent complete reassembly and eventually cause timeout.
Worked example: original total length4020 bytes, header20, payload4000; MTU1500, DF=0. Maximum nonfinal payload=floor((1500−20)/8)×8=1480. Payload pieces are1480,1480,1040. Their total lengths are1500,1500,1060; offsets0,185,370; MF flags1,1,0. Sum payloads to4000, not4020. Wire IP bytes now total4060 because two additional headers were added. MTU is not a payload allowance.
Refragmentation example: the middle fragment above has original offset185 and payload1480 with MF1. If its next MTU is620, payload chunks are600,600,280, offsets185,260,335 and total lengths620,620,300. All three retain MF1 because original data still follows even after this middle piece. Offsets do not restart at zero. The no-options assumption matters: copied options can affect fragment header lengths in real IPv4.
5. Pitfalls and checks
Write down address block size and alignment before host counts. Distinguish host address, network prefix and next-hop address. Prefix length is bits, IHL is32-bit words, fragment offset is8-byte units, and total length/MTU are bytes. For fragments verify payload conservation, total length≤MTU, nonfinal alignment and original-relative offsets. IPv4 fragmentation behavior must not be generalized to IPv6 routers, which do not fragment forwarded packets.
Original practice: six single-correct MCQs
These original teaching questions are not previous-year questions. Choose exactly one answer.
P01. How many ordinary usable host addresses does a /27 subnet provide under the stated convention?
A. 27 B. 30 C. 32 D. 62
Answer: B
A: 27 is prefix length, not host count.
B: Five host bits give32−2=30.
C: 32 includes network and broadcast.
D: 62 belongs to /26.
P02. Which is the network address of 192.0.2.173/27?
A. 192.0.2.128 B. 192.0.2.160 C. 192.0.2.173 D. 192.0.2.191
Answer: B
A: 128 starts the preceding block.
B: 173 lies in160…191.
C: This is a host address inside the block.
D: 191 is the broadcast address.
P03. Matching routes are /0, /8 and /24. Which prefix wins longest-prefix matching?
A. /0 B. /8 C. /24 D. The first listed route
Answer: C
A: The default is least specific.
B: /8 is less specific than /24.
C: 24 matched bits give the most specific route.
D: Listing order does not determine specificity.
P04. A 2020-byte IPv4 datagram has a 20-byte header, DF=0 and outgoing MTU1020. What are the two fragment offsets?
A. 0 and1000 B. 0 and125 C. 0 and127 D. 20 and1020
Answer: B
A: Offsets use8-byte units, not bytes.
B: Each payload is1000 bytes;1000/8=125.
C: The IP header must not be counted in payload offset.
D: Offsets exclude headers and start at zero.
P05. An oversized IPv4 packet reaches a router with DF set. What is the normal specified response?
A. Fragment regardless of DF B. Reassemble it at that router C. Drop it and normally report fragmentation needed through ICMP D. Increase the link MTU automatically
Answer: C
A: DF prohibits fragmentation.
B: The router cannot solve oversize by reassembly.
C: The drop and error feedback support path MTU discovery, subject to ICMP rules.
D: The router does not automatically change physical link MTU to fit a packet.
P06. Which two /25 prefixes aggregate exactly into 198.51.100.0/24?
A. 198.51.100.0/25 and198.51.100.128/25 B. 198.51.100.0/25 and198.51.101.0/25 C. 198.51.100.64/25 and198.51.100.128/25 D. 198.51.100.0/25 and198.51.100.0/25
Answer: A
A: These are the aligned lower and upper halves.
B: They are not the two halves of this /24.
C: 64 is not a canonical /25 boundary.
D: Repeating the lower half does not cover the upper half.
Sources and scope
Aligned to the 2026 course. This lesson covers the stated slice, not the entire Computer Networks syllabus. All numerical examples and questions are original. No claim of 2027 completeness.
Sign in to keep your progress. Sign in