Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Sharing one public address

After this lesson: I can explain how many devices share one public address.

50 min lessonNo commands

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

WordWhat it meansExample
Public addressan IP address that works across the internet203.0.113.7
Private addressan IP address that works only inside one network192.168.1.23
Routera device that passes traffic between networks
Default gatewaythe router a device sends all outside traffic to
NATthe router swapping private addresses for its public one
Port forwardinga 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 withExampleOften seen in
10.10.0.4.7Large offices and cloud networks
172.16. to 172.31.172.20.0.5Containers and some offices
192.168.192.168.1.23Homes and small offices

The cells students fill in are left blank in this preview.

Try it: private or public

Code: python
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

Code: bash
$ 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.23

NAT 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 portOutside, as the routerTalking to
192.168.1.23:51544203.0.113.7:40001shop.example.com:443
192.168.1.31:49210203.0.113.7:40002shop.example.com:443
192.168.1.23:51545203.0.113.7:40003mail.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.

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.