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

Free lesson

Addresses and masks: who shares a network

After this lesson: I can tell if two devices are on the same network.

45 min lesson4 commandsStatic routing lab: build routes on a small network in your browser

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

WordWhat it meansExample
IP addressthe number that names a device on a network192.168.1.20
Octetone of the four numbers in an address, 0 to 255
Maskthe number that says which part of an address names the network255.255.255.0
Network partthe octets every device on one network shares
Host partthe octets that pick one device on the network
Private rangeaddresses 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

AddressMaskNetwork partHost part
192.168.1.20255.255.255.0 (/24)192.168.120
10.0.12.2255.255.255.0 (/24)10.0.122
172.16.5.9255.255.0.0 (/16)172.165.9

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

Ask Python for a /24 mask

Command
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

Command
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

DeviceAddressNetwork part with /24Same as the till?
Till laptop192.168.1.20192.168.1.0Itself
Old printer192.168.1.50192.168.1.0Yes
New printer192.168.2.50192.168.2.0No

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

Ask h1 how it reaches its router

Command
sudo ip netns exec h1 ip route get 10.0.1.1

Shown 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

Command
sudo ip netns exec h1 ip route get 10.0.12.2

Shown 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

RangeStarts withOften found in
10.0.0.0/810Large schools and companies
172.16.0.0/12172.16 up to 172.31Medium networks
192.168.0.0/16192.168Homes 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.

About this lab and its source: Static routing lab: build routes on a small network in your browser

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