Communication Networks · Visualized

Network Address Translation (NAT)

Addressing & Names

How devices get numbers, find each other on the LAN, and turn human-readable names into addresses.

7 interactive subtopics — each one animated, step-through and explained.

Network Address Translation (NAT)

Addressing & Names

IPv4 addresses ran out decades ago; NAT is the workaround that became infrastructure. Your router owns the single public address; every device behind it gets a private one (10/8, 172.16/12 or 192.168/16). Outgoing packets are rewritten — source IP and port replaced by the public IP and a fresh port — and the router remembers the mapping so replies find their way back.

How Network Address Translation (NAT) Works

  1. An inside host sends to the internet; its packet reaches the NAT gateway with a private source address.
  2. The router swaps the source to its public IP and picks an unused public port (e.g. 192.168.1.5:51322 → 93.184.216.1:40001).
  3. The mapping {inside IP:port ↔ public port} is stored in the NAT table with a timeout.
  4. The reply arrives at that public port; the table converts it back to the original inside host.
  5. Mapping entries expire after idleness — which is why long-lived connections send keepalives.

Network Address Translation (NAT) Worked Example

Try it: Two laptops open websites at the same time — watch the NAT table.

Laptop A:51322 → public :40001; Laptop B:51322 → public :40002. Both replies land on different public ports, and the table routes each to the right laptop. Their local ports collided; the NAT port pool prevents that from ever reaching the internet.

Laptop A192.168.1.5Laptop B192.168.1.6NAT router93.0.0.7 (public)web.example.com:443api.example.net:443from .5:513221 public IP · N private hosts
host A host B return traffic NAT translation
Stage 1 / 5
Laptop A (192.168.1.5:51322) sends to web.example.com:443. Its packet reaches the NAT router.

Network Address Translation (NAT): Key Facts to Remember

Why it worksprivate RFC1918 ranges are reused in millions of homes — never routed publicly
Costsbreaks true peer-to-peer (needs hole punching), and complicates hosting servers behind NAT
IPv6 sayswith 128-bit addresses every device can be globally routable — NAT becomes optional again

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses

See how packets really travel

Networks are built on the structures and algorithms you can watch step by step — queues, trees, and routing algorithms.