home LANprivateinternetpublic
Envelope seal: whose address it carries (blue/pink private, teal public)Yellow tablet on the router: the translation table, one bar per rowLanes: the home LAN on the left, the internet on the rightRed ×: no row matches, the packet is droppedThe laptop (192.168.1.10) and the phone (192.168.1.11) both talk to 198.51.100.20:443 from port 50000. The router rewrites each source to its one public address, 203.0.113.7, with its own public port (61001, 61002), and keeps a row per conversation so it can rewrite the replies back. A packet from a stranger matches no row and is dropped; idle rows expire. 203.0.113.7, 198.51.100.20 and 192.0.2.99 are RFC 5737 documentation addresses; 192.168.1.0/24 is RFC 1918 private space. Port numbers are illustrative.

Why NAT

  1. IPv4 has about 4.3 billion addresses, too few for every device. So your home gets one public address, 203.0.113.7, on the router. The laptop and phone use private ones (192.168.1.x) that the internet never carries.

Out and back

Sharing one address

Limits

The headers, field by field

;; step 1/11 · one-address · local
;; at home router + laptop + phone
IPv4 addresses: 2^32 = 4,294,967,296 (RFC 791)
home LAN 192.168.1.0/24 · private space, RFC 1918:
  10.0.0.0/8
  172.16.0.0/12
  192.168.0.0/16
  laptop 192.168.1.10 · phone 192.168.1.11 · router inside 192.168.1.1
router outside: 203.0.113.7 (the one public address)
private addresses are not routed on the public internet,
so the router must translate: NAT (RFC 3022)

Many routers keep the inside port when it is free (port preservation, RFC 4787 §4.2.1). Here the router hands out 61001, 61002, … so the swap is easy to see. Real routers also note the server’s address and port in each row and may accept replies only from it (RFC 4787 §5).