Forty devices, one address
A small office has 30 laptops, a few phones and two printers. The broadband provider gives it one address on the internet.
Yet every laptop browses at the same time, and each reply reaches the right desk. The router does this by keeping notes. In this lesson you read those notes.
By the end of this lesson
Note
I can explain how many devices share one public address.
Key words
| Word | What it means | Example |
|---|---|---|
| Public address | an IP address that works across the internet | 203.0.113.7 |
| Private address | an IP address that works only inside one network | 192.168.1.23 |
| Router | a device that passes traffic between networks | |
| Default gateway | the router a device sends all outside traffic to | |
| NAT | the router swapping private addresses for its public one | |
| Port forwarding | a rule that lets outside requests reach one inside device |
The cells students fill in are left blank in this preview.
Private addresses stay inside
Three ranges of addresses are kept for private use. Any office or home can use them, so thousands of networks use the same ones.
That is fine because they never travel across the internet. Only the router's public address does. If you see 192.168. or 10. at the start, you are looking at a private address.
Worked example: the private ranges
| Starts with | Example | Often seen in |
|---|---|---|
| 10. | 10.0.4.7 | Large offices and cloud networks |
| 172.16. to 172.31. | 172.20.0.5 | Containers and some offices |
| 192.168. | 192.168.1.23 | Homes and small offices |
The cells students fill in are left blank in this preview.
Try it: private or public
def is_private(address):
# The three private ranges: 10.x.x.x, 172.16.x.x to 172.31.x.x, 192.168.x.x
parts = address.split(".")
first = int(parts[0])
second = int(parts[1])
if first == 10:
return True
if first == 172 and second >= 16 and second <= 31:
return True
if first == 192 and second == 168:
return True
return False
for address in ["192.168.1.23", "10.0.4.7", "203.0.113.10", "172.20.0.5"]:
print(address, "private:", is_private(address))
# Add "172.32.0.5" to the list. Is it private?
The default gateway is the way out
Your laptop can reach devices on its own network directly. For anything else, it sends the traffic to one router: the default gateway.
Below is real output from ip route on a Linux laptop. The first line names the gateway. The second says which addresses are local. If the gateway is wrong or down, the laptop can still print, but cannot reach any website.
Real output from ip route
$ ip route
default via 192.168.1.1 dev wlan0
192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.23NAT keeps a table of who asked
When a laptop sends a request out, the router swaps the laptop's private address for its public one. It also picks a port, and writes a line in its NAT table.
When the reply comes back to that port, the router reads the line. It swaps the address back and sends the reply to the right laptop. A reply with no line in the table is dropped.
Worked example: the router's NAT table
| Inside device and port | Outside, as the router | Talking to |
|---|---|---|
| 192.168.1.23:51544 | 203.0.113.7:40001 | shop.example.com:443 |
| 192.168.1.31:49210 | 203.0.113.7:40002 | shop.example.com:443 |
| 192.168.1.23:51545 | 203.0.113.7:40003 | mail.example.com:443 |
The cells students fill in are left blank in this preview.
A common mistake
Warning
Many people think each office laptop has its own address on the internet. Behind NAT, they all share the router's public address. So a website log shows the office, not the person. To find one laptop, you need the router's NAT records too.