Appearance
NAT (Network Address Translation)
NAT translates private IP addresses ↔ public IP addresses, allowing multiple devices on a LAN to share a single public IP.
Why NAT?
- IPv4 exhaustion — not enough public IPs for every device.
- Private IPs (RFC 1918) are not routable on the internet.
- NAT sits at the router/gateway and translates addresses.
How NAT Works (Basic Flow)
LAN Device Router (NAT) Internet Server
192.168.1.10 →→→ 203.0.113.1 →→→ 93.184.216.34
(private IP) (public IP) (destination)- Device sends packet with src:
192.168.1.10 - Router replaces src with public IP:
203.0.113.1 - Server responds to
203.0.113.1 - Router translates back and forwards to
192.168.1.10
Types of NAT
1. Static NAT
- One-to-one mapping — one private IP ↔ one public IP.
- Permanent, manually configured.
- Used for servers that need to be reachable from outside.
2. Dynamic NAT
- One-to-one but from a pool of public IPs.
- Private IP gets assigned a public IP from the pool temporarily.
- If pool is exhausted → connection fails.
3. PAT — Port Address Translation (Most Common)
- Also called NAT Overload or NAPT.
- Many-to-one — multiple devices share one public IP.
- Uses port numbers to distinguish connections.
- This is what your home router does.
PAT Example:
192.168.1.10:5001 → 203.0.113.1:5001
192.168.1.11:5002 → 203.0.113.1:5002
192.168.1.12:5003 → 203.0.113.1:5003NAT Translation Table
| Private IP | Private Port | Public IP | Public Port | Destination |
|---|---|---|---|---|
| 192.168.1.10 | 4321 | 203.0.113.1 | 5001 | 93.184.216.34:80 |
| 192.168.1.11 | 4322 | 203.0.113.1 | 5002 | 93.184.216.34:80 |
NAT Advantages & Disadvantages
| Advantages | Disadvantages |
|---|---|
| Conserves public IPs | Breaks end-to-end connectivity |
| Hides internal network (security) | Complicates P2P / VoIP / gaming |
| Easy LAN management | Adds latency (translation overhead) |
| No need to renumber LAN on ISP change | Stateful — NAT table can overflow |
NAT Traversal
- STUN — discovers public IP/port
- TURN — relays traffic through a server
- UPnP — devices request port mappings automatically
- Port Forwarding — manually map external port to internal device
NAT vs PAT
| NAT | PAT | |
|---|---|---|
| Mapping | IP to IP | IP+Port to IP+Port |
| Public IPs needed | One per device | One for all devices |
| Most common? | No | Yes (home routers) |