Recall warm-up
- Why must a router recompute the IPv4 header checksum whenever it modifies a header field?
Stuck? Peek at 3.2.2 IPv4 fragmentation, offsets, MF bit & multi-hop re-fragmentation
- Max data per fragment:
d_max = ⌊(MTU − H)/8⌋ × 8(must be a multiple of 8 B). - Offset =
start_byte / 8(relative to original datagram); MF = 1 on all fragments except the very last of the original datagram (MF = 0). - Original payload from last fragment (MF=0):
8 × Offset + (TotalLength − 4×HLEN). - Reassembly: ONLY at final destination host.
- Max data per fragment:
- Approximately how many total addresses exist in the 32-bit IPv4 space?
Stuck? Peek at 3.1.2 Classful addressing (A–E) and special IPv4 addresses
- Classes by 1st octet: A = 0–127 (
0, 8 net bits), B = 128–191 (10, 16 net bits), C = 192–223 (110, 24 net bits), D = 224–239 (1110, multicast), E = 240–255 (1111, reserved). - Usable hosts = 2ʰ − 2 (exclude host all-0s = network address, host all-1s = directed broadcast).
- Specials:
0.0.0.0= this host (src only);255.255.255.255= limited broadcast (local LAN only);127.x.y.z= loopback.
- Classes by 1st octet: A = 0–127 (
- What is the generic name from Phase 1 for the identifier that tells a host which running program (process) a message is for?
Stuck? Peek at 1.1.3 Encapsulation, headers, PDU names, addresses and devices per layer
- Encapsulation: payload + header (+ trailer at data link); decapsulation in reverse.
- PDUs: message (app) → segment (transport) → packet/datagram (network) → frame (data link) → bits.
- Addresses: link (per hop, changes) · network (end to end, fixed) · which-program id · names.
- Devices: hub/repeater 1 · bridge/switch 2 · router 3 · gateway/host up to 7.
- Efficiency = data / (data + all headers + trailer).
The Hook
Your home Wi-Fi router has a phone, two laptops, a tablet, and a smart TV connected — 5 devices, each needing an IPv4 address. Multiply that by a billion homes and offices, and 4.3 billion IPv4 addresses would have run out decades ago!
The clever workaround that kept IPv4 alive is private addressing + Network Address Translation (NAT): millions of homes reuse the exact same private IP addresses inside their LANs, and the home router translates all of them into a single public IPv4 address whenever packets go out to the Internet!
Predict First
Two laptops inside your house (192.168.1.10 and 192.168.1.20) both send requests to the same external server 93.184.216.34 through your home router, which replaces both source IPs with its single public IP 203.0.113.5. When the server replies to 203.0.113.5, how on earth does your router know whether the reply is for Laptop 1 or Laptop 2?
By also translating and recording a 16-bit port number! The router maps Laptop 1 to public port 5001 and Laptop 2 to public port 5002 in its NAT translation table. When the server replies to 203.0.113.5:5001, the router looks up 5001 and forwards the packet to 192.168.1.10!
Core Concept
RFC 1918 Private IPv4 Address Ranges
Three blocks of IPv4 addresses are reserved as private addresses: they are free for anyone to use inside a LAN, and Internet backbone routers NEVER route packets carrying a private source or destination IP.
| Private Block (CIDR) | Address Range | # of /24s (Class C equiv) | Total Addresses |
|---|---|---|---|
| 10.0.0.0/8 | 10.0.0.0 – 10.255.255.255 | 65,536 (1 Class A) | 2²⁴ = 16,777,216 |
| 172.16.0.0/12 | 172.16.0.0 – 172.31.255.255 | 4,096 (16 Class Bs) | 2²⁰ = 1,048,576 |
| 192.168.0.0/16 | 192.168.0.0 – 192.168.255.255 | 256 (256 Class Cs) | 2¹⁶ = 65,536 |
Port-Based NAT (NAPT) & the Translation Table
In Network Address and Port Translation (NAPT), a NAT router with one public IP 203.0.113.5 maintains a NAT translation table mapping (Private IP, Private Port) ↔ (Public IP, Assigned NAT Port):
What NAT Modifies & Architectural Trade-offs
When a packet passes through a NAPT router, what header fields must be rewritten?
- Outgoing (LAN → WAN): Rewrites Source IP, Source Port, IPv4 Header Checksum (plus TTL decrement), AND the Transport-layer Checksum (which covers IP addresses and port numbers).
- Incoming (WAN → LAN): Rewrites Destination IP, Destination Port, and both checksums.
- The Inbound Problem: An outside host cannot initiate a connection to a private host unless the NAT table already has an entry (created by an outgoing packet or manual port forwarding).
Putting it together
- Private IPv4 ranges (10/8, 172.16/12, 192.168/16) can be reused inside any LAN but are never routed on the public Internet.
- NAPT lets an entire private LAN share one public IPv4 address by multiplexing connections using 16-bit port numbers in a NAT translation table.
- Outgoing packets have their Source IP:Port rewritten; incoming replies have their Destination IP:Port rewritten.
Visual
| Direction | Source IP : Port | Destination IP : Port | NAT Table Action |
|---|---|---|---|
| Host A → NAT (LAN side) | 192.168.1.10 : 3345 | 93.184.216.34 : 80 | Create mapping (192.168.1.10:3345 ↔ 203.0.113.5:5001) |
| NAT → Server (WAN side) | 203.0.113.5 : 5001 | 93.184.216.34 : 80 | Rewrite Src IP & Src Port; recompute checksums |
| Server → NAT (WAN side) | 93.184.216.34 : 80 | 203.0.113.5 : 5001 | Look up WAN port 5001 in NAT table |
| NAT → Host A (LAN side) | 93.184.216.34 : 80 | 192.168.1.10 : 3345 | Rewrite Dst IP & Dst Port; recompute checksums |
Worked Examples
How many total IPv4 addresses exist in each of the three RFC 1918 private blocks (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16)?
Show the full solution
• 10.0.0.0/8: 2³²⁻⁸ = 2²⁴ = 16,777,216 addresses.
• 172.16.0.0/12: 2³²⁻¹² = 2²⁰ = 1,048,576 addresses.
• 192.168.0.0/16: 2³²⁻¹⁶ = 2¹⁶ = 65,536 addresses.
Which of the following IPv4 addresses are private RFC 1918 addresses? (i) 172.20.5.1 (ii) 172.32.0.1 (iii) 192.169.1.1 (iv) 10.250.1.1
Show the full solution
• 172.20.5.1: 2nd octet 20 is in 16..31 → Private.
• 172.32.0.1: 2nd octet 32 is outside 16..31 → Public.
• 192.169.1.1: 2nd octet is 169 ≠ 168 → Public.
• 10.250.1.1: 1st octet is 10 → Private.
Two internal hosts H1 (10.0.0.1) and H2 (10.0.0.2) both pick the exact same source port 4000 and simultaneously send packets to the same external server 198.51.100.9:80 through a NAPT router with public IP 203.0.113.1. Does a collision occur in the NAT table?
Show the full solution
No! The NAPT router picks two different external source ports on its public IP — for example, mapping (10.0.0.1, 4000) ↔ (203.0.113.1, 6001) and (10.0.0.2, 4000) ↔ (203.0.113.1, 6002). When replies return to port 6001 vs 6002, the router demultiplexes them cleanly to H1 and H2.
GATE Traps
- 172.32.x.y is NOT private! The Class B private block is
172.16.0.0/12(172.16.0.0 – 172.31.255.255), not all of172.x.y.z. - NAT is NOT a pure Layer-3 device: Because NAPT reads and rewrites 16-bit port numbers (and transport checksums), it crosses the boundary between Layer 3 (Network) and Layer 4 (Transport).
Memory Hook
10/8, 172.16/12 (16 to 31), 192.168/16 — Outgoing rewrites SOURCE; Incoming rewrites DESTINATION!
Connect the Dots
We now know how IPv4 datagrams are addressed, subnetted, fragmented, and translated at network edges. After the Chapter 3.3 Lock-in, Chapter 3.4 answers the biggest question of the Network Layer: how do routers automatically discover the shortest path across the Internet?
Self-Test
- MCQ
Which of the following IPv4 addresses is a PUBLIC (globally routable) IPv4 address?
- 10.255.255.1
- 172.30.10.5
- 172.32.10.5
- 192.168.0.254
- NAT
How many Class B (/16) networks are combined to form the RFC 1918 private block 172.16.0.0/12?
Write your answer before opening the key.
- MCQ
When an outgoing packet from a private LAN host passes through a NAPT router toward an external server, which addresses/ports in the packet does the NAPT router rewrite?
- Destination IP and Destination Port
- Source IP and Source Port
- Source IP and Destination IP
- Only the Source MAC address
- MSQ
Which of the following are valid technical criticisms or limitations of NAPT?
- It violates strict layering because a network-layer router modifies transport-layer port numbers.
- External hosts cannot initiate connections to internal private hosts without pre-configured port forwarding.
- It requires recomputing the IPv4 header checksum on every translated packet.
- It increases the number of public IPv4 addresses required by a home network.
Rule Card
- Private IPv4 ranges:
10.0.0.0/8,172.16.0.0/12(172.16..31.x.y),192.168.0.0/16. - NAPT table: maps
(Private IP, Private Port) ↔ (Public IP, NAT Port). - Rewrites: Outgoing → Source IP + Source Port; Incoming → Destination IP + Destination Port (+ checksums).
Concept Ledger
- private address ranges (10/8, 172.16/12, 192.168/16)
- NAT (Network Address Translation)
- NAT translation table
- port number (16-bit Foundation preview)
- NAPT (port-based NAT)
- NAT pros and cons
Answer Vault
Try the questions first. Open when you are ready to check.
Warm-up answers
- Because the header checksum is the 1’s-complement sum over all 16-bit words of the IPv4 header; changing any header bit invalidates the checksum.
- 2³² ≈ 4.29 billion addresses.
- The "which-program identifier" (formalised below as a port number).
Self-test answers
- C — 172.16.0.0/12 covers 172.16.0.0 to 172.31.255.255; therefore 172.32.10.5 is outside the private range and is a public IP.
- A: Inside 10.0.0.0/8.
- B: Inside 172.16.0.0/12 (16 ≤ 30 ≤ 31).
- D: Inside 192.168.0.0/16.
- 16 — A /12 block contains 2¹⁶⁻¹² = 2⁴ = 16 contiguous /16 blocks (172.16.0.0/16 through 172.31.0.0/16).
- B — On the outgoing path (LAN → WAN), NAPT replaces the private Source IP and Source Port with the router’s public IP and an assigned NAT port.
- A: Destination IP and Destination Port are rewritten on the incoming reply (WAN → LAN).
- C: The server’s Destination IP is not changed on the outgoing request.
- D: A regular router changes only L2 MAC addresses + L3 TTL/checksum, whereas NAPT also rewrites Source IP and Source Port.
- ABC — NAPT modifies L4 ports (layering violation), blocks unsolicited inbound connections, and must recompute checksums. Its whole purpose is to REDUCE public IPv4 usage.
- D: NAPT reduces public IP usage (allowing an entire LAN to share 1 public IP).
Flashcards
- List the three RFC 1918 private IPv4 address blocks in CIDR notation.
Reveal answer
10.0.0.0/8, 172.16.0.0/12 (172.16.0.0 – 172.31.255.255), and 192.168.0.0/16. - What does a NAPT router rewrite on an OUTGOING packet vs an INCOMING reply?
Reveal answer
Outgoing: Source IP and Source Port. Incoming: Destination IP and Destination Port (plus checksums in both directions). - How does NAPT allow two internal hosts using the same source port to talk to the same server simultaneously?
Reveal answer
By assigning two different external port numbers on the router’s public IP in the NAT translation table.
Exam shortcuts
- 172.16.0.0/12 boundary check:
/12means the first 4 bits of the 2nd octet are fixed to0001₂(16), and the last 4 bits vary0000₂..1111₂(+0..+15) → 172.16.x.y through 172.31.x.y. — never falling for the 172.32.x.y or 172.15.x.y GATE trap. - Outgoing vs Incoming rewrite symmetry: Outgoing changes Source (IP + Port); Incoming changes Destination (IP + Port). — tracing NAT packet headers quickly.