IPv4 subnetting: practice problems with step-by-step solutions
Also called: subnet mask · CIDR
Free IPv4 subnetting practice problems with diagrams, hints and full worked solutions. New values every time, at three levels: hosts per subnet, dividing a network, address ranges.
Free practice problemEasy
How many usable host addresses H are there in an IPv4 subnet with prefix /29?
Every device on an IPv4 network has an IP address, for example 192.168.10.37. It is 32 bits long, written as four numbers from 0 to 255. Each number is one byte, called an octet.
An address has two parts. The first part says which network the device is on. The second part says which host (device) it is inside that network.
Think of a street address: the street name is the network, the house number is the host.
A subnet is one such network. Splitting a big network into subnets keeps traffic local and lets an administrator give each department its own range.
The prefix tells you where the split is. In 192.168.10.37/24 the first 24 bits are the network part, and the last 8 bits are the host part.
Self-check An address is written as 10.1.2.3/20. How many bits are in the host part?
12
20
32
8
Answer: 12. An address has 32 bits. The prefix /20 gives 20 network bits, so 32 − 20 = 12 bits are left for the host. 20 is the network part, not the host part.
2Prefix, mask and number of hosts
The same split can be written as a subnet mask: 32 bits with 1s for the network part and 0s for the host part, written like an address.
A /24 mask is 24 ones and 8 zeros: 255.255.255.0. A /16 mask is 255.255.0.0.
When the prefix ends inside an octet, that octet gets the first few bits set. These are the only values a mask octet can have:
Example: /27 is 24 + 3 bits, so the mask is 255.255.255.224.
With h host bits there are 2h addresses. Two of them cannot be given to a device: the first is the network address and the last is the broadcast address.
H = 2(32 − p) − 2
For /24: 2⁸ − 2 = 254 usable hosts. For /27: 2⁵ − 2 = 30.
Access lists use a wildcard mask, the inverse of the subnet mask: each octet is 255 minus the mask octet. For /27 that is 0.0.0.31.
Self-check What is the subnet mask of a /26 network?
255.255.255.192
255.255.255.252
255.255.255.26
255.255.255.64
Answer: 255.255.255.192. /26 is 24 + 2 bits, and an octet with the first 2 bits set is 128 + 64 = 192. 64 is the value of the second bit only, and 252 is the octet for 6 bits.
3The method step by step
Hosts and masks:
Find the host bits: h = 32 − p.
Usable hosts: H = 2h − 2.
To go from a mask to a prefix, count the 1-bits: 255 is 8, 224 is 3, and so on.
Dividing a network:
You need N subnets. Borrow the smallest number of bits n with 2n ≥ N from the host part.
The new prefix is the old prefix plus n.
Each subnet has 2(32 − new prefix) − 2 usable hosts.
To fit h hosts in one subnet, find the smallest number of host bits with 2bits − 2 ≥ h.
The range of an address:
Find the octet where the prefix ends. Its block size is 256 minus the mask octet.
The network address is the largest multiple of the block size that is not above the address octet.
The broadcast address is the network address plus the block size minus 1.
Usable hosts are everything in between: network + 1 up to broadcast − 1.
4A worked example
Follow every step. Try to predict the next one before you open it.
Worked example
The network 192.168.10.0/24 must be divided into at least 10 equal subnets. If you borrow as few bits as possible, how many usable hosts H does each subnet have?
1
Count the bits you have
A /24 network has 32 − 24 = 8 host bits to share out.
2
Borrow enough bits
Borrowing n bits gives 2n subnets. 2³ = 8 is too few. 2⁴ = 16 is enough.
So you borrow n = 4 bits.
3
Find the new prefix
p = 24 + 4 = 28
That leaves 32 − 28 = 4 host bits.
4
Count the usable hosts
H = 2⁴ − 2 = 14
5
Check the answer
16 subnets of 16 addresses each use 16 · 16 = 256 addresses, exactly the size of the /24 network. The numbers fit.
Answer
Each /28 subnet has H = 14 usable hosts.
5Finding the range of an address
Take the host 10.20.130.90/27. The prefix ends in the fourth octet, and the mask is 255.255.255.224.
block size = 256 − 224 = 32
The subnets in the fourth octet start at 0, 32, 64, 96, … The address octet 90 lies between 64 and 95.
When the prefix ends in the third octet, for example /20, the same steps work on the third octet. The fourth octet is then 0 for the network and 255 for the broadcast.
Self-check A host has the address 10.20.72.98/27. What is the fourth octet of its network address?
127
64
96
98
Answer: 96. The block size is 256 − 224 = 32. The multiples are 0, 32, 64, 96, 128, and 96 is the largest one not above 98. 127 is the broadcast, and 64 uses a block of 64 (a /26).
6Common mistakes
Forgetting the −2. The network address and the broadcast address are not usable hosts.
Using the prefix as the number of host bits. The host bits are 32 − p.
Borrowing too many bits. Take the smallest n that gives enough subnets.
Computing the block size in the wrong octet. Use the octet where the prefix ends.
Taking the address itself as the network address. Round down to a multiple of the block size.
Self-check How many usable host addresses are there in a /27 subnet?
27
30
32
5
Answer: 30. 32 − 27 = 5 host bits, and 2⁵ − 2 = 30. 32 forgets that the network and broadcast addresses cannot be used.
7How exam questions look
Easy: hosts per subnet. Usable hosts for a prefix, the mask of a prefix, the prefix of a mask, or a wildcard mask.
Medium: dividing a network. How many subnets of a given prefix fit, how many bits to borrow and the hosts per subnet, or the smallest subnet for a number of hosts.
Hard: address ranges. The network, broadcast or last usable address of a host, a summary route for several networks, or VLSM allocation.
For a summary route, write the octet that changes in binary and count how many leading bits all networks share.
In VLSM, give the largest LAN its subnet first, then the next one directly after it, each with its own prefix.
How many usable host addresses H are there in an IPv4 subnet with prefix /26?
/26
Find H
Show hints
The host part has 32 − p bits.
Subtract 2 for the network and broadcast addresses.
32 − 26 = 6.
Show the answer and the step-by-step solution
IPv4 subnetting: an address has 32 bits. The prefix /p says how many leading bits identify the network; the remaining 32 − p bits number the hosts. A subnet has 2³²⁻ᵖ addresses, but the first (network address) and last (broadcast address) cannot be given to hosts, so 2³²⁻ᵖ − 2 hosts fit. Exceptions: a /31 (point-to-point link, RFC 3021) uses both of its 2 addresses for hosts, and a /32 is one single address (a single host or a loopback).
Host bits
32 − 26 = 6
Usable hosts
26 − 2 = 64 − 2 = 62
Answer
H = 62
Example 2Medium
A subnet uses the mask 255.255.252.0. How many usable host addresses H does it have?
255.255.252.0
Find H
Show hints
Convert the mask to a prefix length by counting its one-bits.
Then H = 2³²⁻ᵖ − 2.
p = 22.
Show the answer and the step-by-step solution
IPv4 subnetting: an address has 32 bits. The prefix /p says how many leading bits identify the network; the remaining 32 − p bits number the hosts. A subnet has 2³²⁻ᵖ addresses, but the first (network address) and last (broadcast address) cannot be given to hosts, so 2³²⁻ᵖ − 2 hosts fit. Exceptions: a /31 (point-to-point link, RFC 3021) uses both of its 2 addresses for hosts, and a /32 is one single address (a single host or a loopback).
Prefix length
255.255.252.0 = /22
Usable hosts
210 − 2 = 1022
Answer
H = 1022
Example 3Hard
A host has the address 10.20.178.194/27. What is the fourth octet x of the last usable host address in its subnet?
10.20.178.194/27
Find x
Show hints
With /27, each subnet holds 2³²⁻ᵖ addresses in the last octet, so subnets start at multiples of that size.
The network address is the multiple at or below 194; the broadcast address is the next multiple minus 1.
block size = 25 = 32.
Show the answer and the step-by-step solution
IPv4 subnetting: an address has 32 bits. The prefix /p says how many leading bits identify the network; the remaining 32 − p bits number the hosts. A subnet has 2³²⁻ᵖ addresses, but the first (network address) and last (broadcast address) cannot be given to hosts, so 2³²⁻ᵖ − 2 hosts fit. Exceptions: a /31 (point-to-point link, RFC 3021) uses both of its 2 addresses for hosts, and a /32 is one single address (a single host or a loopback).
Block size
25 = 32
Subnet of this host
network: ⌊194/32⌋·32 = 192
broadcast: 192 + 32 − 1 = 223
usable hosts: 193 … 222
Answer
x = 222
Questions and answers
What is IPv4 subnetting?
Every device on an IPv4 network has an IP address, for example 192.168.10.37. It is 32 bits long, written as four numbers from 0 to 255. Each number is one byte, called an octet.
An address has two parts. The first part says which network the device is on. The second part says which host (device) it is inside that network.
How do I solve IPv4 subnetting problems step by step?
IPv4 subnetting: an address has 32 bits. The prefix /p says how many leading bits identify the network; the remaining 32 − p bits number the hosts. A subnet has 2³²⁻ᵖ addresses, but the first (network address) and last (broadcast address) cannot be given to hosts, so 2³²⁻ᵖ − 2 hosts fit. Exceptions: a /31 (point-to-point link, RFC 3021) uses both of its 2 addresses for hosts, and a /32 is one single address (a single host or a loopback).
What are common mistakes in IPv4 subnetting?
Count all zero-bits of the mask, including the eight in the last octet (0).
What do the IPv4 subnetting exercises cover?
Easy: hosts per subnet
Medium: dividing a network
Hard: address ranges
Every problem has new values, so you learn the method instead of an answer. Stuck? Open a small hint first, and the full explanation only when you need it.
How practising works
Every problem has new values, so you learn the method instead of an answer.
Stuck? Open a small hint first, and the full explanation only when you need it.
Your progress, mistakes and saved problems are kept, so you can review before the exam.