3 IPv4 Subnetting Practice
Learn to calculate IPv4 subnet boundaries, determine host capacity, choose prefix lengths, and allocate variable-sized subnets.
Address structure and prefixes
An has bits. In , a prefix such as /26 means that bits identify the network, leaving .
The has the prefix’s number of leading 1 bits followed by 0 bits. For example, the mask for /26 is 255.255.255.192. The prefix determines the number of addresses in the subnet: , where is the prefix length.
For an ordinary subnet with a prefix from /0 through /30, the typical usable host count is the total address count minus two. The two excluded addresses are the and ; usable host addresses lie between them.
Find subnet boundaries
The can be found by performing a bitwise AND between the IP address and its . Alternatively, use the : find the first mask octet that is neither 255 nor 0, then calculate the block size as . The network begins at a multiple of that block size in the changing octet.
To identify the subnet containing an address, find the block in that octet that includes the address’s value. The start of the block gives the ; the next block’s start is one address after the . Equivalently, the is the last address in the current block. The same method applies when the changing octet is not the last octet.
Apply the
These common prefix sizes show the corresponding masks and typical host capacities:
/24: mask255.255.255.0; total addresses and usable hosts./25: mask255.255.255.128; total addresses and usable hosts./26: mask255.255.255.192; total addresses and usable hosts./27: mask255.255.255.224; total addresses and usable hosts./28: mask255.255.255.240; total addresses and usable hosts./29: mask255.255.255.248; total addresses and usable hosts./30: mask255.255.255.252; total addresses and usable hosts.
Example: a prefix that changes the last octet
For 192.168.10.77/26, the mask is 255.255.255.192, so the last-octet block size is . Blocks begin at .0, .64, .128, and .192. Since .77 falls in the block from .64 through .127, the network is 192.168.10.64 and the broadcast is 192.168.10.127. The is 192.168.10.65–192.168.10.126, containing addresses.
Example: a prefix that changes the third octet
For 10.23.77.9/20, the mask is 255.255.240.0. The third octet is the changing octet, with a block size of . Its blocks begin at ; the value lies in the block from through . The network is 10.23.64.0, the broadcast is 10.23.79.255, and the usable range is 10.23.64.1–10.23.79.254. There are typical usable host addresses.
Choose a prefix for a host requirement
To choose a prefix for a required number of hosts, find the smallest number of for which is at least the host requirement. The prefix length is then .
For a requirement of at least hosts, gives usable addresses, which is insufficient, while gives , which is enough. The resulting prefix is /26, with total addresses and typical usable hosts.
For a requirement of at least usable hosts, provide , which is insufficient. provide , so the smallest suitable prefix is /24, providing typical usable addresses.
Allocate variable-sized subnets
allows subnets with different sizes to be allocated from one address range. Allocate the largest host requirement first so that smaller requirements can fit into the remaining space. Each allocation must begin on a valid boundary for its block size.
For example, allocate subnets from 192.168.10.0/24 for requirements of , , , and usable hosts:
For hosts, use
/25, which has usable hosts. Allocate192.168.10.0/25; the usable range is192.168.10.1–192.168.10.126, and the broadcast is192.168.10.127.For hosts, use
/26, which has usable hosts. Allocate192.168.10.128/26; the usable range is192.168.10.129–192.168.10.190, and the broadcast is192.168.10.191.For hosts, use
/27, which has usable hosts. Allocate192.168.10.192/27; the usable range is192.168.10.193–192.168.10.222, and the broadcast is192.168.10.223.For hosts, use
/30, which has usable hosts. Allocate192.168.10.224/30; the usable range is192.168.10.225–192.168.10.226, and the broadcast is192.168.10.227.
These allocations use block sizes of , , , and addresses, respectively.
Practice calculations and answers
Divide a /24 into /27 subnets
A /27 uses blocks of addresses. A /24 contains addresses, so it can be divided into such subnets. For 192.168.20.0/24, the network addresses are 192.168.20.0, 192.168.20.32, 192.168.20.64, 192.168.20.96, 192.168.20.128, 192.168.20.160, 192.168.20.192, and 192.168.20.224. The first, third, and last are 192.168.20.0, 192.168.20.64, and 192.168.20.224.
Calculate a subnet with a /21 prefix
For 172.16.35.200/21, the mask is 255.255.248.0. The changing octet is the third, with block size . The block containing begins at and ends at . The network is 172.16.32.0, the broadcast is 172.16.39.255, and the usable range is 172.16.32.1–172.16.39.254.
Exceptions and CIDR context
The usual rule of subtracting two addresses for the usable host count has exceptions. A /31 prefix is used for two-address point-to-point links, and a /32 identifies a single address. A /31 can therefore serve a supported point-to-point link instead of using a conventional /30 subnet when two usable host addresses are required.
CIDR uses prefix lengths rather than historical address classes.