IPv4, CIDR and translation
Read an IPv4 length as including its IP header unless explicitly described as payload. CIDR is binary prefix arithmetic; fragmentation is byte arithmetic with an eight-byte offset unit. Keep those units separate.
6.1 IPv4 fields used in forwarding
Past papers · CS 2014–2026 (23 papers): 5 questions, 5 marks
| Field | Width | Interpretation |
|---|---|---|
| Version; IHL | 4 bits each | Version 4; header length in 32-bit words |
| Total length | 16 bits | Header plus payload, in bytes; maximum 65,535 |
| Identification | 16 bits | Shared by fragments of the original datagram |
| Flags | 3 bits | Reserved zero, DF (do not fragment), MF (more fragments) |
| Fragment offset | 13 bits | Payload position relative to original payload, in 8-byte units |
| TTL | 8 bits | Hop-limiting field; normally decreased by one per forwarding router |
| Protocol | 8 bits | Directly carried protocol; TCP is 6, OSPF is 89 |
| Header checksum | 16 bits | IPv4 header only |
| Source; destination address | 32 bits each | Network endpoints, except explicit translation |
| Options and padding | Up to 40 bytes | Header stays a multiple of four bytes |
Ordinary forwarding modifies TTL and checksum. Fragmentation can also change total length, offset, MF and options; it preserves the original Identification. IP does not recover lost fragments. Reassembly is at the destination, even if a later link has a larger MTU. Routing protocol packets and transport packets can both be direct IP payloads; Protocol is not an application port number.
6.2 CIDR masks, ranges and allocation
Past papers · CS 2014–2026 (23 papers): 6 questions, 10 marks
An IPv4 address has 32 bits. In a / prefix the first bits identify the block and the remaining bits vary. An address written with a prefix need not itself be the block's first address; obtain the canonical block by masking. An allocation advertised as a block start must be aligned.
| Prefix | Dotted mask | Addresses | Ordinary usable hosts |
|---|---|---|---|
| /16 | 255.255.0.0 | 65,536 | 65,534 |
| /20 | 255.255.240.0 | 4096 | 4094 |
| /21 | 255.255.248.0 | 2048 | 2046 |
| /22 | 255.255.252.0 | 1024 | 1022 |
| /23 | 255.255.254.0 | 512 | 510 |
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 6 |
| /30 | 255.255.255.252 | 4 | 2 |
6.3 Longest-prefix matching and aggregation
Past papers · CS 2014–2026 (23 papers): 7 questions, 14 marks
A route matches when the destination masked to that route's prefix equals the route's network number. Among all matches choose the longest prefix, regardless of table order. A /0 default matches every address but loses to any more specific match. Route metrics resolve alternatives to the same prefix; they do not override a more specific matching prefix.
To aggregate equal-size blocks into one exact block, they must be contiguous, their number a power of two, and their first address aligned to the combined block size. More generally the range must exactly equal a binary prefix range. A common prefix covering a range may include unwanted extra addresses. Preserve more-specific entries if different destinations need different next hops.
Counting subnets in a diagram means counting separately addressed network segments, including separately addressed router-to-router links. A switch does not by itself create an additional IP subnet. A firewall's role and interface addressing must be supplied; do not infer the count from device count alone.
6.4 Fragmentation and repeated fragmentation
Past papers · CS 2014–2026 (23 papers): 8 questions, 15 marks
If a datagram exceeds the outgoing MTU and DF is clear, a source or router can fragment it. If DF is set, the router cannot fragment it. Each fragment carries its own IP header. The original transport header remains at the start of the original IP payload; it is not copied into every fragment.
Two successive MTUs split existing fragments; offsets remain relative to the original IP payload.
6.5 NAT and port translation
Past papers · CS 2014–2026 (23 papers): 1 question, 1 mark
Basic NAT maps an internal address to an external address. Network address and port translation (NAPT, often called PAT) can map many internal endpoints to one public address by assigning distinct translated ports. A connection's mapping must support reverse translation of replies.
| Direction for an ordinary outbound TCP flow | Address/port rewritten |
|---|---|
| Internal to external | Source IP; source TCP port if port translation is used |
| Reply from external | Destination IP; destination TCP port back to the internal endpoint |
Changing an IP address requires an IPv4 checksum update. TCP checksum also changes because its pseudo-header includes IP addresses; changing a TCP port also affects it. Ordinary fixed-length address/port replacement does not change the IP Total Length. Destination NAT is a separate mapping policy, so the outbound-source rule is not a claim about all possible NAT deployments. See RFC 3022.
Private blocks commonly used inside NAT are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. NAT itself is neither encryption nor a general proof of security.
Last-minute recall
- IHL counts four-byte words; Total Length counts bytes; fragment offset counts eight-byte units.
- IPv4 checksum protects only the header.
- Mask an arbitrary address to find its canonical network.
- Check block capacity, alignment and containment separately.
- Longest matching prefix wins.
- Subtract the IP header before finding fragment payload capacity.
- Refragment each parent independently; preserve original-payload offsets.
- MF=0 identifies the last original-payload fragment, not every parent's last child.
- Reassembly occurs at the destination.
- NAT modifies checksums as well as mapped addresses/ports.