CS Atlas GATE 2027
Computer Networks course
0 / 90 complete

Computer Networks/Phase 3 · Network Layer

Lesson 3.3 · Item 51 of 90

Network Address Translation (NAT): private ranges, NAPT & trade-offs

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

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

    Read lesson 3.2.2

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

    Read lesson 3.1.2

  3. 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).

    Read lesson 1.1.3

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/810.0.0.0 – 10.255.255.25565,536 (1 Class A)2²⁴ = 16,777,216
172.16.0.0/12172.16.0.0 – 172.31.255.2554,096 (16 Class Bs)2²⁰ = 1,048,576
192.168.0.0/16192.168.0.0 – 192.168.255.255256 (256 Class Cs)2¹⁶ = 65,536
The three RFC 1918 private IPv4 ranges — memorise the exact boundaries (especially 172.16..31)!

Port-Based NAT (NAPT) & the Translation Table

Foundation — Port number (preview for NAPT): A port number is a 16-bit identifier (0–65535) carried in the transport-layer header that tells which running program (process) on a host a packet belongs to. Phase 4 (Lesson 4.1) covers ports in full detail; here we only use the port number as an extra tag in the NAT 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):

Host A (192.168.1.10)NAT Router (203.0.113.5)Server (93.184.216.34)1. Src 192.168.1.10:3345 → Dst 93.184.216.34:802. Table: 192.168.1.10:3345 ↔ 203.0.113.5:50013. Src 203.0.113.5:5001 → Dst 93.184.216.34:804. Reply: Src 93.184.216.34:80 → Dst 203.0.113.5:50015. Lookup :5001 → rewrite Dst to 192.168.1.10:33456. Reply delivered to 192.168.1.10:3345
Outgoing packet: NAT rewrites Source IP + Source Port. Incoming reply: NAT rewrites Destination IP + Destination 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).
Advantages of NAT
1. Saves millions of public IPv4 addresses (1 public IP for a whole LAN). 2. Easy to change ISP without renumbering internal hosts. 3. Hides internal hosts from unsolicited inbound connections.
Objections / Problems
1. Layering violation: an L3 router peeks into and modifies L4 port numbers. 2. Breaks the end-to-end argument (hosts cannot directly address each other). 3. Recomputing checksums adds per-packet work.
Why engineers both love and complain about NAT.

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

DirectionSource IP : PortDestination IP : PortNAT Table Action
Host A → NAT (LAN side)192.168.1.10 : 334593.184.216.34 : 80Create mapping (192.168.1.10:3345 ↔ 203.0.113.5:5001)
NAT → Server (WAN side)203.0.113.5 : 500193.184.216.34 : 80Rewrite Src IP & Src Port; recompute checksums
Server → NAT (WAN side)93.184.216.34 : 80203.0.113.5 : 5001Look up WAN port 5001 in NAT table
NAT → Host A (LAN side)93.184.216.34 : 80192.168.1.10 : 3345Rewrite Dst IP & Dst Port; recompute checksums
Complete 4-step packet header trace across a NAPT router.

Worked Examples

Easy

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.

Medium

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.

GATE

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 of 172.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

  1. MCQ

    Which of the following IPv4 addresses is a PUBLIC (globally routable) IPv4 address?

    1. 10.255.255.1
    2. 172.30.10.5
    3. 172.32.10.5
    4. 192.168.0.254
  2. 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.

  3. 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?

    1. Destination IP and Destination Port
    2. Source IP and Source Port
    3. Source IP and Destination IP
    4. Only the Source MAC address
  4. MSQ

    Which of the following are valid technical criticisms or limitations of NAPT?

    1. It violates strict layering because a network-layer router modifies transport-layer port numbers.
    2. External hosts cannot initiate connections to internal private hosts without pre-configured port forwarding.
    3. It requires recomputing the IPv4 header checksum on every translated packet.
    4. 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

  1. 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. 2³² ≈ 4.29 billion addresses.
  3. The "which-program identifier" (formalised below as a port number).

Self-test answers

  1. 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.
  2. 16 — A /12 block contains 2¹⁶⁻¹² = 2⁴ = 16 contiguous /16 blocks (172.16.0.0/16 through 172.31.0.0/16).
  3. 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.
  4. 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

  1. List the three RFC 1918 private IPv4 address blocks in CIDR notation.
    Reveal answer10.0.0.0/8, 172.16.0.0/12 (172.16.0.0 – 172.31.255.255), and 192.168.0.0/16.
  2. What does a NAPT router rewrite on an OUTGOING packet vs an INCOMING reply?
    Reveal answerOutgoing: Source IP and Source Port. Incoming: Destination IP and Destination Port (plus checksums in both directions).
  3. How does NAPT allow two internal hosts using the same source port to talk to the same server simultaneously?
    Reveal answerBy 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: /12 means the first 4 bits of the 2nd octet are fixed to 0001₂ (16), and the last 4 bits vary 0000₂..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.

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.