One office, three groups of devices
A small firm has one office and sixty devices. Tills, printers, staff laptops and guest phones all share one network.
The owner wants the tills kept apart from the guests. Before any cable moves, someone must cut one block of addresses into smaller blocks.
That cut is what this lesson teaches.
By the end of this lesson
Note
I can split a network into subnets.
Key words
| Word | What it means | Example |
|---|---|---|
| IP address | a number that names one device on a network | 10.0.12.77 |
| Prefix | the number after the slash: how many bits name the network | /24 |
| Subnet mask | the prefix written as four numbers | 255.255.255.0 |
| Subnet | a smaller network cut from a bigger one | |
| Network address | the first address of a block, which names the block itself | |
| Broadcast address | the last address of a block, used to speak to every device in it |
The cells students fill in are left blank in this preview.
An address is thirty-two bits
An IPv4 address is 32 bits long. We write it as four numbers from 0 to 255, split by dots.
Each number is one byte. Computers work with the bits. People read the dotted form.
Worked example: one address in bits
| Part | Number | Bits |
|---|---|---|
| First | 10 | 00001010 |
| Second | 0 | 00000000 |
| Third | 12 | 00001100 |
| Fourth | 77 | 01001101 |
The cells students fill in are left blank in this preview.
Read the lab's addresses
netlab statusShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
What the lab shows
Each machine lists its cables and an address with a prefix, such as 10.0.12.1/24.
Find the two addresses on the link between r1 and r2. They share the first 24 bits, so they are on one network.
The prefix splits network from device
The number after the slash is the prefix. It says how many bits, counted from the left, name the network.
The remaining bits name the device. In 10.0.12.77/24, the first 24 bits name the network and the last 8 bits name the device.
A longer prefix leaves fewer bits for devices.
Worked example: common prefixes
| Prefix | Mask | Addresses | Usable hosts |
|---|---|---|---|
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /30 | 255.255.255.252 | 4 | 2 |
The cells students fill in are left blank in this preview.
Ask Python for a 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.
A common mistake
Warning
Many people think a /24 holds 256 devices. It holds 256 addresses. The first names the network and the last is the broadcast address. Neither can go to a device, so a /24 holds 254 hosts.
Cutting a block into subnets
To cut a block, make the prefix longer. Each extra bit doubles the number of subnets and halves the size of each.
A /24 cut by two bits gives four /26 subnets. Each holds 64 addresses.
The new networks start at multiples of 64: 0, 64, 128 and 192.
Worked example: four subnets
| Network | First host | Last host | Broadcast |
|---|---|---|---|
| 192.168.10.0/26 | 192.168.10.1 | 192.168.10.62 | 192.168.10.63 |
| 192.168.10.64/26 | 192.168.10.65 | 192.168.10.126 | 192.168.10.127 |
| 192.168.10.128/26 | 192.168.10.129 | 192.168.10.190 | 192.168.10.191 |
| 192.168.10.192/26 | 192.168.10.193 | 192.168.10.254 | 192.168.10.255 |
The cells students fill in are left blank in this preview.
Let Python cut the block
python3 -c "print(list(__import__('ipaddress').ip_network('192.168.10.0/24').subnets(new_prefix=26)))"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Going further: subnets of different sizes
Real groups are rarely the same size. Cut 192.168.20.0/24 for 60 tills, 25 staff laptops and 10 guest phones.
Give the biggest group its block first, then the next biggest, each at the next free multiple of its size. Write the network, the first host, the last host and the broadcast for each.
Check every row with your calculate function, then say how many addresses are left over.