Chapter 6

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

FieldWidthInterpretation
Version; IHL4 bits eachVersion 4; header length in 32-bit words
Total length16 bitsHeader plus payload, in bytes; maximum 65,535
Identification16 bitsShared by fragments of the original datagram
Flags3 bitsReserved zero, DF (do not fragment), MF (more fragments)
Fragment offset13 bitsPayload position relative to original payload, in 8-byte units
TTL8 bitsHop-limiting field; normally decreased by one per forwarding router
Protocol8 bitsDirectly carried protocol; TCP is 6, OSPF is 89
Header checksum16 bitsIPv4 header only
Source; destination address32 bits eachNetwork endpoints, except explicit translation
Options and paddingUp to 40 bytesHeader 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 /pp prefix the first pp 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.

PrefixDotted maskAddressesOrdinary usable hosts
/16255.255.0.065,53665,534
/20255.255.240.040964094
/21255.255.248.020482046
/22255.255.252.010241022
/23255.255.254.0512510
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/29255.255.255.24886
/30255.255.255.25242

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.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 flowAddress/port rewritten
Internal to externalSource IP; source TCP port if port translation is used
Reply from externalDestination 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.

Revise offline: the whole Computer Networks handbook as one PDF

47 pages · 2.1 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections