Skip to content

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)
  1. Device sends packet with src: 192.168.1.10
  2. Router replaces src with public IP: 203.0.113.1
  3. Server responds to 203.0.113.1
  4. 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:5003

NAT Translation Table

Private IPPrivate PortPublic IPPublic PortDestination
192.168.1.104321203.0.113.1500193.184.216.34:80
192.168.1.114322203.0.113.1500293.184.216.34:80

NAT Advantages & Disadvantages

AdvantagesDisadvantages
Conserves public IPsBreaks end-to-end connectivity
Hides internal network (security)Complicates P2P / VoIP / gaming
Easy LAN managementAdds latency (translation overhead)
No need to renumber LAN on ISP changeStateful — 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

NATPAT
MappingIP to IPIP+Port to IP+Port
Public IPs neededOne per deviceOne for all devices
Most common?NoYes (home routers)