Lesson 03: Private Networks

NAT & Private IPs

There are roughly 15 billion devices connected to the internet, but only 4 billion IPv4 addresses. How is this mathematically possible? The answer is Network Address Translation (NAT) and RFC 1918.

Private IP Ranges

In 1996, the internet engineers realized we were running out of addresses. They reserved three blocks of IPs exclusively for private networks. These addresses are unroutable on the public internet:

Your laptop, your phone, and your smart TV probably all have 192.168.x.x addresses. But when you load a webpage, the web server doesn't see your private IP (because it can't route data back to it). It sees your router's public IP.

How NAT Works

When your laptop sends a packet to the internet, the router intercepts it. It changes the Source IP from your private IP to its own public IP, and changes the Source Port to a random port it generates. It then records this swap in a NAT Translation Table.

When the web server replies to the router's public IP and port, the router checks its table, rewrites the destination back to your laptop's private IP and port, and forwards it to you.

NAT Router Simulator

Click to send a request from an internal device. Watch how the router translates the private source address into its own public address using the NAT table.

๐Ÿ’ป
Laptop (Private)
192.168.1.100
Router's NAT Table
Public IP: 203.0.113.10
๐ŸŒŽ
Server (Public)
142.250.190.46
Internal Address (Private) Mapped Address (Public) Status

NAT is the duct tape that kept the IPv4 internet alive for an extra 20 years. However, it completely breaks peer-to-peer protocols. If two laptops on different home networks try to talk directly to each other, both are hidden behind NAT routers that will block incoming traffic unless a translation rule was already established. This is why technologies like STUN and TURN exist for WebRTC and gaming.

Check yourself

1. What does a NAT router do when an internal device requests a webpage?

NAT (Network Address Translation) swaps the unroutable private address with its own routable public address, and maintains a state table so it knows where to send the response when it arrives.