Practical guide
CIDR subnetting: calculate networks, masks, and host ranges
Learn IPv4 CIDR subnetting with the binary formula, /24 and /31 worked examples, edge cases, and a subnet calculator.
Updated
CIDR expresses an IPv4 network as an address plus a prefix length, such as 192.168.1.0/24. The prefix is the number of fixed network bits. The remaining 32 − prefix bits identify addresses inside that network.
CIDR formulas
- Total addresses =
2^(32 − prefix). - Subnet mask = the prefix bits set to 1 followed by host bits set to 0.
- Network address = IP address bitwise AND subnet mask.
- Broadcast address = network address with every host bit set to 1.
For conventional subnets from /0 through /30, usable hosts usually equal total addresses minus the network and broadcast addresses. RFC 3021 is the important exception: both addresses in a /31 can be used on a point-to-point link. A /32 represents one address or host route.
Worked /24 example
Input: 192.168.1.42/24. A /24 leaves eight host bits, so the block contains 2^8 = 256 addresses. The mask is 255.255.255.0, the network is 192.168.1.0, and the broadcast is 192.168.1.255. Under conventional subnet use, the host range is 192.168.1.1 through 192.168.1.254.
The CIDR and subnet calculator performs the same bitwise calculation and exposes the /31 and /32 rules. For a compact version of this example, see how many IPs are in a /24.
Common mistake: treating every prefix alike
Subtracting two addresses from every block produces impossible negative counts at /31 and /32. Another common mistake is assuming an address ending in .0 must be a network address; the prefix determines the boundary, not the final octet alone.
Practical subnetting checklist
- Confirm that the input is IPv4 and each octet is 0–255.
- Convert the prefix to a mask.
- Apply the mask to find the network boundary.
- Calculate the broadcast and address count.
- Apply /31 or /32 semantics before reporting usable hosts.
- Check whether the result falls inside a private IPv4 range.
Sources
The address and prefix model follows RFC 4632. Point-to-point /31 behavior follows RFC 3021.