Networking · interactive
NAT and private networks
There aren't enough IPv4 addresses for every device, so your home or office network uses private addresses and the router shares one public address. It rewrites every packet on the way out and keeps a table to send replies back.
Private network
- Laptop 192.168.1.10
- Phone 192.168.1.11
- TV 192.168.1.12
Router
inside 192.168.1.1
outside 203.0.113.7
Internet
Only ever sees 203.0.113.7
NAT table
| inside | outside | remote |
|---|---|---|
| empty | ||
Three devices with private 192.168 addresses. The internet only knows the router's one public address.
Private ranges stay inside
10/8, 172.16/12 and 192.168/16 aren't routed on the internet. Millions of networks reuse them.
That's why your laptop is 192.168.something.
Rewrite the source
The router swaps the private address and port for its public address and a free port, and records the mapping.
Port numbers tell the connections apart.
Look up the reply
Replies arrive at the public port. The table says which device and port to rewrite them to.
Mappings expire after a period of silence.
No mapping, no entry
Inbound traffic nobody asked for is dropped. Port forwarding adds a fixed mapping; cloud NAT gateways do the same job for private subnets.
Peer-to-peer apps need tricks (STUN, TURN) to get through.
In production
Tools and technologies
NAT is in every home router and cloud network.
Not tied to one language — use these names when you search docs or design a system.