2 Subnet and Host Range Calculations
Learn how IPv4 prefixes and subnet masks determine subnet boundaries, address counts, usable host ranges, and subnet membership, including prefix-specific exceptions.
IPv4 prefixes and masks
An IPv4 address is bits and is usually written as four decimal octets, such as 192.168.1.77. A such as specifies how many leading bits identify the network; the remaining bits identify addresses within that network. CIDR uses this prefix length instead of the older address classes.
A prefix has network bits and host bits. Its consists of leading bits followed by bits.
Address counts and block sizes
The total number of addresses in a prefix is determined by its host-bit count:
For ordinary subnets from through , the number of usable host addresses is typically:
The two excluded addresses are the , where all host bits are , and the directed , where all host bits are . For example, a contains total addresses and typically usable host addresses.
To find the by hand, locate the first mask octet that is not 255 and subtract its value from . For , the last mask octet is 192, so the is . The subnet boundaries in that octet are , , , and .
Finding subnet and host ranges
To find a subnet's , , and :
Find the and .
Locate the block containing the given address. The block's first address is the .
Identify the block's last address; it is the .
For an ordinary subnet, the runs from one address after the to one address before the .
For 192.168.1.77/26, the mask is 255.255.255.192, and the in the last octet is . The blocks are .0–.63, .64–.127, .128–.191, and .192–.255. Since .77 falls in .64–.127, the is 192.168.1.64, the is 192.168.1.127, and the is 192.168.1.65–192.168.1.126, containing addresses.
A prefix can cross an octet boundary. For 172.16.35.123/20, the mask is 255.255.240.0. The in the third octet is ; the third-octet blocks include , , and . Because is in , the is 172.16.32.0, the is 172.16.47.255, and the is 172.16.32.1–172.16.47.254. This prefix has total addresses and typically usable hosts.
Subnet size and splitting a block
A longer prefix leaves fewer host bits and therefore creates smaller subnets. Splitting a into subnets borrows bits, creating subnets. Each has total addresses and typically usable host addresses.
Under modern subnetting practice, all definable subnets are usable, including the first and last.
Checking
An address belongs to a subnet if applying the to it produces that subnet's . In bitwise notation:
Another way to check is to see whether the address falls between the subnet's network and broadcast addresses, inclusive. For example, 192.168.1.100 belongs to 192.168.1.64/26 because it falls within .64–.127; 192.168.1.130 does not.
Special prefixes
The usual rule of subtracting from the total address count has exceptions. A is used on point-to-point links, where both addresses are interpreted as host addresses and there is no conventional network/broadcast exclusion. A identifies one address and is commonly used as a host route.