6 IPv4 Subnetting Practice
Learn how IPv4 prefixes and subnet masks define networks, calculate subnet boundaries and host ranges, and choose subnet sizes for addressing needs.
IPv4 subnetting and prefixes
Subnetting divides an block into smaller networks. It helps organize devices, limit broadcast traffic to each subnet, and allocate address space to fit network needs.
An is 32 bits long. states how many leading bits identify the network, and the remaining bits identify addresses within it. CIDR uses explicit prefix lengths rather than relying on address classes.
Subnet masks and address counts
A has 32 bits: network bits are 1 and host bits are 0. The is the number of leading 1 bits. Dotted-decimal masks show those bits in four octets.
Common prefix sizes have these address counts and ordinary usable host counts:
/24: mask255.255.255.0;256total addresses and254usable hosts./25: mask255.255.255.128;128total addresses and126usable hosts./26: mask255.255.255.192;64total addresses and62usable hosts./27: mask255.255.255.224;32total addresses and30usable hosts./28: mask255.255.255.240;16total addresses and14usable hosts./29: mask255.255.255.248;8total addresses and6usable hosts./30: mask255.255.255.252;4total addresses and2usable hosts.
For ordinary IPv4 subnets, usable host addresses exclude the and . /31 is a special case commonly used on point-to-point links, where both addresses can be assigned to the two endpoints. /32 represents one address.
A prefix can fall within any octet. For example, /20 has mask 255.255.240.0: eight network bits in each of the first two octets and four more in the third, for 20 network bits total.
A method for calculating subnets
For a prefix /p, the host-bit count is . The total address count is . For ordinary subnets, the usable host count is usually the total address count minus .
To calculate a subnet:
Find the host bits: .
Find the total addresses: .
Find the usable hosts: usually the total addresses minus .
Find the by keeping the network bits and setting all host bits to
0. Equivalently, bitwise-AND the IP address with its .Find the by keeping the network bits and setting all host bits to
1.Find the : one address after the through one before the .
When the mask changes within an octet, calculate the as in that octet. Subnet network numbers advance by that .
Worked subnet calculation
For 192.168.10.77/26, the mask is 255.255.255.192. The last-octet is , so subnet boundaries are .0, .64, .128, and .192. The address .77 falls between .64 and .127, so it belongs to that subnet.
:
192.168.10.64:
192.168.10.127:
192.168.10.65–192.168.10.126Total addresses:
Usable hosts:
The IP address identifies a device within the block; the prefix determines which block it belongs to.
Planning subnet sizes
Choose a prefix that provides enough host addresses for the devices on a subnet, allowing room for growth. For example, 25 devices need at least 27 addresses under the ordinary network-and-broadcast rule. A /27 provides 32 total addresses and 30 usable host addresses, so it fits.
A /24 can be divided into eight /27 subnets because /27 has three more network bits than /24. The number of equal subnets is . For 10.20.30.0/24, the subnet network addresses are:
10.20.30.0/2710.20.30.32/2710.20.30.64/2710.20.30.96/2710.20.30.128/2710.20.30.160/2710.20.30.192/2710.20.30.224/27
often used for internal addressing are 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16.
Practice and answers
For each exercise, find the , , , and usable host count. Assume ordinary subnets unless noted.
192.168.5.130/25172.16.4.200/22Divide
192.168.8.0/24into equal subnets that each support at least 50 usable hosts. Find the number of subnets and the first subnet’s range.
Answers
/25has 128 addresses, and boundaries in the last octet advance by 128. The is192.168.5.128; the is192.168.5.255; the is192.168.5.129–192.168.5.254; and there are 126 usable hosts./22has mask255.255.252.0, so the third-octet is . The third-octet boundary containing 4 is 4. The is172.16.4.0; the is172.16.7.255; the is172.16.4.1–172.16.7.254; and there are 1,022 usable hosts.A
/26provides 62 usable hosts, so use/26. A/24yields four/26subnets. The first is192.168.8.0/26:192.168.8.0,192.168.8.63, and192.168.8.1–192.168.8.62.