CIDR and IPv4 Subnetting: Worked Examples for Developers

CIDR notation combines an IPv4 address with a prefix length. The prefix says how many leading bits identify the network.

Worked /24 example

For 192.168.20.42/24, the first 24 bits identify the network. The mask is 255.255.255.0, so the network is 192.168.20.0 and the broadcast address is 192.168.20.255. In traditional host-addressing terms, the range between them is 192.168.20.1 through 192.168.20.254.

Worked /26 example

A /26 leaves 6 host bits, giving blocks of 64 addresses. In the last octet the block boundaries are 0, 64, 128 and 192.

Input:     192.168.10.77/26
Block:     192.168.10.64 - 192.168.10.127
Network:   192.168.10.64
Broadcast: 192.168.10.127
Traditional host range: 192.168.10.65 - 192.168.10.126

The useful mental shortcut is block size, but binary reasoning is more general: mask off the host bits for the network and set host bits to 1 for the broadcast address.

Worked /30 example

A /30 has four addresses per block. 10.0.0.9/30 falls in the block 10.0.0.8–10.0.0.11. Traditionally, .8 is network, .11 broadcast and .9–.10 are host addresses. /30 is therefore common in older point-to-point subnetting examples.

/31 and /32 are special cases

Do not mechanically subtract two usable addresses for every prefix. RFC 3021 defines /31 use for point-to-point links, where both addresses can be endpoints and the traditional network/broadcast distinction is not used the same way. A /32 identifies one IPv4 address. Calculators should surface these caveats rather than applying a classroom formula blindly.

Cloud “usable address” counts can differ

Cloud providers may reserve addresses inside a subnet for platform functions. CIDR math describes the address block; provider policy describes what you may assign. When planning capacity, use the provider’s current subnet-reservation documentation in addition to the calculated range.

Subnet debugging checklist

  • Write the prefix and dotted mask explicitly.
  • Calculate the containing block boundary, not just the host count.
  • Check whether the target IP is actually inside the expected range.
  • Separate subnet arithmetic from routing, firewall, VLAN and NAT policy.
  • For /31-/32, apply the intended operational use rather than generic “network/broadcast” assumptions.

Use the CIDR Range Calculator or IP Subnet Calculator to check arithmetic, then validate routing and platform reservations in the environment where the network will exist.

References

About the review

This guide is maintained by William. Technical claims are checked against primary or authoritative references where applicable. See How We Test CodeNimbleTools for the site-wide review and correction process.