3 IPv4 Subnet Calculation Practice
Learn to interpret IPv4 prefixes, calculate subnet boundaries and address ranges, divide networks into equal subnets, and verify the results.
IPv4 addresses, masks, and prefixes
An contains 32 bits, usually written as four decimal octets. A marks the leading network bits and the remaining bits for addresses within the network. gives the number of network bits after a slash: for example, /24 has 24 network bits and 8 .
In binary, a valid has a continuous run of 1 bits followed by 0 bits. The is found by applying a bitwise AND to the IP address and the mask.
For an ordinary IPv4 subnet with , the total and usable address counts are:
The subtraction excludes the , which is the first address in the block, and the , which is the last. These formulas apply to ordinary subnets; special-purpose prefixes can have different rules.
Find a subnet boundary and address range
For a prefix that does not end on an octet boundary, find the octet where the mask changes from 255 to a smaller value. Calculate the in that octet:
Subnet network boundaries are multiples of this . Find the multiple at or below the address's value in that octet; this is the network boundary. The next boundary minus one gives the .
Worked example: 192.168.10.77/26
The prefix leaves , so the mask is
255.255.255.192.In the fourth octet, the is .
The fourth-octet boundaries are
0,64,128, and192. Since77is between64and127, the is192.168.10.64.The next boundary is
128, so the is192.168.10.127.The usable range is
192.168.10.65–192.168.10.126. There are .
Check that .77 falls between the network and broadcast addresses. The block contains 64 total addresses.
Divide a network into equal subnets
To create at least equal-size subnets, borrow the smallest number of such that:
Add to the original prefix length. The resulting subnets are equal in size, and each has fewer than the original network.
Worked example: divide 192.168.20.0/24 into four subnets
Four subnets require borrowed bits because .
The new prefix length is , or
/26.Each subnet has 6 , 64 total addresses, and 62 .
The is 64, so the fourth-octet boundaries are
0,64,128, and192.
The four subnets are:
Network
192.168.20.0/26; usable range192.168.20.1–192.168.20.62; broadcast192.168.20.63.Network
192.168.20.64/26; usable range192.168.20.65–192.168.20.126; broadcast192.168.20.127.Network
192.168.20.128/26; usable range192.168.20.129–192.168.20.190; broadcast192.168.20.191.Network
192.168.20.192/26; usable range192.168.20.193–192.168.20.254; broadcast192.168.20.255.
The four blocks are consecutive, each contains 64 addresses, and they do not overlap. Together they cover the original /24, which contains 256 addresses.
Worked subnet calculations
Find the range for 10.1.5.200/27
The mask is 255.255.255.224, giving a of 32. The address falls in the fourth-octet block from .192 through .223. The is 10.1.5.192, the is 10.1.5.223, and the usable range is 10.1.5.193–10.1.5.222. With 5 , there are .
Find the range for 172.16.8.130/25
The mask is 255.255.255.128, giving a of 128. The address falls in the fourth-octet block from .128 through .255. The is 172.16.8.128, the is 172.16.8.255, and the usable range is 172.16.8.129–172.16.8.254. With 7 , there are .
Divide 10.0.4.0/24 into eight equal subnets
Eight subnets require 3 borrowed bits, so the new prefix is /27. The network addresses are 10.0.4.0, 10.0.4.32, 10.0.4.64, 10.0.4.96, 10.0.4.128, 10.0.4.160, 10.0.4.192, and 10.0.4.224. Each subnet contains 32 total addresses and 30 .
Verify subnet calculations
Before accepting a calculation, check that:
The prefix is between
/0and/32, and the mask consists of consecutive 1 bits followed by 0 bits.The given address falls within the calculated network-to-broadcast range.
The lies on a valid block boundary.
The is the last address before the next boundary.
When a network is divided, the number of subnets and their address counts add up to the original block.
In general, use the prefix length to determine the number of network bits and the remaining . Use the mask and to locate subnet boundaries, then identify the , , and usable range. For equal-size subnetting, borrow enough bits to meet the required subnet count, calculate the resulting , and verify that the blocks are aligned, consecutive, and non-overlapping.