← Module 03 · Layer 3: Network

NAT & PAT

Hundreds of private devices, one public IP (Internet Protocol) address, and somehow the replies still find their way back to the right device. This is how.

The problem: Too many devices, too few public addresses

Private IPv4 ranges (like 192.168.0.0/16 or 10.0.0.0/8) can be reused by literally every home and office network on earth, because they're never routed on the public internet. But a device using one of those addresses can't be reached from the internet directly. Something has to translate between the private address inside the network and a real, routable public address at the edge. That something is NAT (Network Address Translation).

It's exactly like an office building with one public street address, where every employee has their own internal extension. Mail addressed to the building's street address still needs a mailroom to figure out which specific desk it's actually for.

Static NAT, dynamic NAT, and PAT

How PAT keeps replies straight

Every outbound connection gets a unique combination of (public IP, public port) assigned to it, and the router keeps a translation table mapping that pair back to the original (private IP, private port) it came from. When a reply comes back addressed to that public IP and port, the router looks up the table and rewrites it back to the correct private device, exactly like a receptionist routing an incoming call to the right desk extension based on which line it came in on.

A 192.168.1.10:5001 B 192.168.1.11:5001 NAT / PAT translation table HOST PRIVATE PUBLIC A :5001 :40001 B :5001 :40002 same private port in, a different public port out GW 203.0.113.9 one public IP, two public ports
Both A and B use source port 5001 internally. PAT rewrites each to a different public port so replies for each come back to the right device.
THE TRADE-OFF NAT MAKES

NAT solved the IPv4 address shortage well enough to buy the internet another two decades, but it breaks true end-to-end connectivity: an outside device can't initiate a connection to a device that's only reachable through PAT, and some protocols need extra workarounds (like STUN, Session Traversal Utilities for NAT, and TURN, Traversal Using Relays around NAT, for real-time voice/video) specifically because of it. IPv6's address space is large enough that most devices don't need NAT at all. Every device just gets its own real, globally routable address.