Study FAQ
How do I calculate the network, broadcast, and usable hosts from an IPv4 prefix?
Also asked as 2
- How can I find the network address, broadcast address, and host range from IPv4 CIDR notation?
- Given an IPv4 address and prefix length, how do I work out the subnet boundaries and usable range?
Answer
In a conventional IPv4 LAN subnet, keep the prefix bits and set all host bits to zero for the network address. Set all host bits to one for the directed broadcast address. The addresses in between are normally usable by hosts.
For 192.0.2.70/27, the mask is 255.255.255.224. The five host bits produce blocks of 32 addresses. The last octet 70 falls in the block from 64 to 95, so the network is 192.0.2.64, the broadcast is 192.0.2.95, and the usable range is 192.0.2.65 through 192.0.2.94. A conventional subnet with h host bits has 2^h minus 2 usable addresses. A /31 on an IPv4 point-to-point link can use both addresses. A /32 identifies one address, with no separate broadcast or host range to calculate.
To size a LAN, pick enough host bits for its usable address requirement. To divide a network into equal-size subnets, extend its prefix by enough bits to produce the required number of blocks. To check whether two addresses are local to one another on a simple Ethernet LAN, apply each host’s configured mask and compare its view of the network for both addresses. If the views disagree, check the masks and each host’s default gateway against the address plan. On the gateway, confirm the intended LAN prefix is present as a connected route.
References
Full explanation
IPv4 Addressing, Subnetting, and Private Address Design
Study guide · 200-301
Read the full explanation