Ravindra BagaleCourses & study guides

Chapter 1: Networking Fundamentals

1.8 NAT (Network Address Translation)

In my sessions, students often ask: "Sir, my laptop shows 192.168.1.5 but Google sees a different IP. Why?" The answer is NAT. Samjla ka? Let's see how it works.

Why: Hundreds of devices on a college network use private IPs, but the college may have only a few public IPs. NAT lets many private devices share one public IP.

How: The router rewrites the source address of outgoing packets from the private IP to its public IP and keeps a translation table so replies go back to the correct device. The variant that also changes ports (many-to-one) is called PAT or NAT overload.

  Private LAN (192.168.1.0/24)                 Internet
 +------------------+
 | Laptop           |  src 192.168.1.10:50001
 | 192.168.1.10     |------+
 +------------------+      |      +-------------------+   src 49.36.12.7:61001
                           +----->|  NAT Router       |----------------------->  google.com
 +------------------+      |      |  Public 49.36.12.7|<-----------------------
 | Phone            |------+      +-------------------+   reply to 49.36.12.7:61001
 | 192.168.1.11     |               NAT table:
 +------------------+               192.168.1.10:50001 <-> 49.36.12.7:61001
NAT type Mapping Example
Static NAT 1 private ↔ 1 public (fixed) EC2 public IP / Elastic IP mapping
Dynamic NAT private ↔ one from a pool of public IPs Enterprise routers
PAT / NAT overload many private → 1 public using ports Home Wi-Fi, AWS NAT Gateway

Ravindra Bagale's Tip

When you design a VPC, never choose 192.168.0.0/16 — it clashes with most home and office Wi-Fi networks, and later VPN connections will break. I prefer something like 10.20.0.0/16 for each project. Plan your CIDR once, carefully; changing it later is painful.