How it works
An IPv4 address is a 32-bit number. A CIDR block such as 10.0.0.0/24 pairs an address with a prefix length: the first N bits are the network part and the remaining bits number the hosts. The subnet mask is simply N ones followed by zeros, and the wildcard mask is its inverse.
The network address is the address ANDed with the mask, and the broadcast address is the network address with every host bit set to 1. Usable hosts lie between them, so a block has 2(32 − prefix) addresses and, for prefixes up to /30, two fewer usable hosts. Splitting a block into subnets adds bits to the prefix: two subnets need one extra bit, four need two, and so on. A count that is not a power of two is rounded up, because CIDR subnets are always powers of two.
Common uses
- Planning address ranges for a VPC, VNet or on-premises VLANs without overlaps.
- Checking which hosts a firewall rule or security group CIDR actually covers.
- Converting between prefix lengths, dotted masks and wildcard masks when configuring routers.
- Carving a /16 into per-environment or per-availability-zone subnets.
