AQA 7517, section 4.9.4.4
A large network can be divided into smaller subnets (subnetworks). A subnet mask shows which part of an IP address is the network identifier and which part is the host identifier.
Why use subnets?
- Organisation: a company can give each department or building its own subnet.
- Performance: broadcasts stay inside one subnet, so there is less traffic.
- Security: traffic between subnets can be controlled with a router or firewall.
- Efficient use of addresses, by choosing sizes that fit.
The subnet mask
A subnet mask is also a 32-bit number, written like an IP address. It has:
- 1s in the positions of the network identifier (and subnet);
- 0s in the positions of the host identifier.
The 1s always come first, followed by the 0s.
| Mask (dotted decimal) | Mask in binary | Network bits |
|---|---|---|
| 255.0.0.0 | 11111111.00000000.00000000.00000000 | 8 |
| 255.255.0.0 | 11111111.11111111.00000000.00000000 | 16 |
| 255.255.255.0 | 11111111.11111111.11111111.00000000 | 24 |
| 255.255.255.192 | 11111111.11111111.11111111.11000000 | 26 |
To write a mask from a number of network bits, write that many 1s and fill the rest of the 32 bits with 0s. For example, 27 network bits gives:
The last octet is .
The mask is sometimes written in CIDR notation, as a slash and the number of 1s: 192.168.1.0/24 means a 24-bit network part.
Using the mask: a bitwise AND
To find the network identifier, perform a bitwise AND between the IP address and the subnet mask. AND gives 1 only if both bits are 1, so:
- where the mask has 1, the IP address bit is kept;
- where the mask has 0, the result is 0 (the host part is removed).
Example 1: mask 255.255.255.0
IP address 192.168.1.25.
The network address is 192.168.1.0. The host part is the last octet, 25.
Example 2: mask 255.255.255.192
The mask isn't a whole number of octets here, so the split is within an octet. IP address 192.168.1.200.
The network address is 192.168.1.192. The host part is the remaining 6 bits: with the first two removed, which is .
Are two devices on the same subnet?
Apply the same mask to both addresses. If the results (network addresses) are identical, the devices are on the same subnet, and can talk directly. If they differ, the traffic must go through a router.
With mask 255.255.255.192:
192.168.1.200gives the network192.168.1.192.192.168.1.230(, AND = ) gives192.168.1.192. Same subnet.192.168.1.70(, AND = ) gives192.168.1.64. Different subnet.
How many hosts?
If the host part has bits, there are usable host addresses (the all-0s network address and the all-1s broadcast address are reserved).
| Mask | Host bits | Usable hosts |
|---|---|---|
| 255.255.255.0 (/24) | 8 | |
| 255.255.255.192 (/26) | 6 | |
| 255.255.255.252 (/30) | 2 |
A longer mask (more 1s) gives more, smaller subnets.
Worked example
Task: a company has the network 10.0.0.0 and wants subnets of 62 hosts. Which mask is needed, and what is the network address for the device 10.0.0.100?
- 62 hosts need 6 host bits (), so the network part is bits, which is the mask
255.255.255.192. - For
10.0.0.100: last octet , AND = . The network address is 10.0.0.64.
Exam tip: write both numbers in binary, line them up, AND them bit by bit, and convert the answer back to decimal. Remember the mask is 1s then 0s, and that the result of the AND gives the network identifier.
Check yourself
What is the purpose of a subnet mask?
To show which part of an IP address is the network identifier and which part is the host identifier.
What network address does 192.168.10.77 with mask 255.255.255.0 give?
192.168.10.0.
How many usable host addresses does a /28 network have?
There are 4 host bits (), so .
How can you tell whether two devices are on the same subnet?
AND each IP address with the subnet mask. If both give the same network address, they are on the same subnet.