Why the printer cannot be found
A small café has a laptop at the till and a printer in the kitchen. The laptop prints fine.
A new printer arrives. Somebody types an address into it by hand, and now nothing prints.
The two addresses look almost the same. The numbers say they are on different networks. This lesson shows how to read them.
By the end of this lesson
Note
I can tell if two devices are on the same network.
Key words
| Word | What it means | Example |
|---|---|---|
| IP address | the number that names a device on a network | 192.168.1.20 |
| Octet | one of the four numbers in an address, 0 to 255 | |
| Mask | the number that says which part of an address names the network | 255.255.255.0 |
| Network part | the octets every device on one network shares | |
| Host part | the octets that pick one device on the network | |
| Private range | addresses kept for inside networks and never used on the internet |
The cells students fill in are left blank in this preview.
An address has two parts
An IP address is four octets, such as 192.168.1.20. The mask says how to split it.
Where the mask octet is 255, that octet is part of the network. Where it is 0, that octet picks the host.
A mask of 255.255.255.0 is often written /24. It means the first 24 bits, three octets, name the network.
Worked example: splitting with a mask
| Address | Mask | Network part | Host part |
|---|---|---|---|
| 192.168.1.20 | 255.255.255.0 (/24) | 192.168.1 | 20 |
| 10.0.12.2 | 255.255.255.0 (/24) | 10.0.12 | 2 |
| 172.16.5.9 | 255.255.0.0 (/16) | 172.16 | 5.9 |
The cells students fill in are left blank in this preview.
Ask Python for a /24 mask
python3 -c "print(__import__('ipaddress').ip_network('10.0.12.0/24').netmask)"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Ask Python for h1's network
python3 -c "print(__import__('ipaddress').ip_interface('10.0.1.2/24').network)"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Same network part, same network
To test two devices, work out each network part with the same mask. If the two network parts match, they share a network.
Then they talk directly. If not, every packet has to go through a router.
A computer does this with a sum called AND on each octet. With a 255 the octet stays. With a 0 it becomes 0.
Worked example: the café's two printers
| Device | Address | Network part with /24 | Same as the till? |
|---|---|---|---|
| Till laptop | 192.168.1.20 | 192.168.1.0 | Itself |
| Old printer | 192.168.1.50 | 192.168.1.0 | Yes |
| New printer | 192.168.2.50 | 192.168.2.0 | No |
The cells students fill in are left blank in this preview.
Ask h1 how it reaches its router
sudo ip netns exec h1 ip route get 10.0.1.1Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Ask h1 how it reaches r2
sudo ip netns exec h1 ip route get 10.0.12.2Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
What h1 decided
The first answer starts 10.0.1.1 dev to-r1. There is no via: the router is on h1's own network, so h1 sends straight to it.
The second answer starts 10.0.12.2 via 10.0.1.1. The network part 10.0.12 is not h1's. So h1 hands the packet to its router, 10.0.1.1.
Some ranges are kept for inside networks
Three ranges are private. Homes, schools and shops reuse them again and again. The internet never carries them.
Every other address can be public, used once in the whole world. Your phone at home usually has a private address such as 192.168.1.x.
Worked example: the three private ranges
| Range | Starts with | Often found in |
|---|---|---|
| 10.0.0.0/8 | 10 | Large schools and companies |
| 172.16.0.0/12 | 172.16 up to 172.31 | Medium networks |
| 192.168.0.0/16 | 192.168 | Homes and small shops |
The cells students fill in are left blank in this preview.
A common mistake
Warning
Many people think two addresses that look close are on the same network. Only the network part counts. With /24, 192.168.1.50 and 192.168.2.50 differ in the third octet, so they are on different networks.
Going further: a mask that is not 255
Some masks split an octet, such as 255.255.255.192, or /26. Python's & works out AND on any number.
Try 200 & 192 and 100 & 192 in Python. Are 192.168.1.100 and 192.168.1.200 on one network with this mask? Check your answer with your same_network.