How it works
An IPv4 address is 32 bits. The CIDR prefix says how many leading bits are the network portion; the rest address hosts. Applying the mask with a bitwise AND gives the network address, and setting all host bits gives the broadcast address.
mask = 0xFFFFFFFF shifted left by (32 − prefix)
network = IP AND mask
broadcast = network OR (NOT mask)
usable hosts = 2^(32 − prefix) − 2
Common prefixes
Subnet cheat sheet and worked example
Example: 192.168.1.130/26 has a block size of 64, so its network is 192.168.1.128, its broadcast address is 192.168.1.191, and usable hosts run from .129 to .190 (62 addresses). A /31 has no network or broadcast address and is used for point-to-point links (RFC 3021), and a /32 is a single host.
Private networks use the RFC 1918 ranges: 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16.
Choosing a subnet size
Leave room for growth: pick the next size up if you're close to the limit.
Wildcard masks
A wildcard mask is the inverse of the subnet mask, used in Cisco ACLs and OSPF. Subtract each octet of the mask from 255: /24 (255.255.255.0) becomes 0.0.0.255, and /26 (255.255.255.192) becomes 0.0.0.63.
Subnetting example: splitting a /24
What about IPv6?
IPv6 addresses are 128 bits. A standard LAN subnet is a /64, which holds 2⁶⁴ addresses, so host counts are never a constraint. Sites typically receive a /48 or /56 and divide it into /64 subnets.
Frequently asked questions
What is CIDR notation?
An IP followed by a slash and prefix length, like 192.168.1.0/24, the prefix is the number of network bits.
Why are two addresses unusable?
The first is the network ID and the last is the broadcast address, so a /24 has 254 usable hosts, not 256.
How many hosts are in a /24?
254 usable hosts out of 256 addresses, after the network and broadcast addresses.
What subnet mask is /26?
255.255.255.192, which gives 64 addresses and 62 usable hosts.
How do I calculate a wildcard mask?
Subtract each octet of the subnet mask from 255. A /27 mask of 255.255.255.224 has a wildcard mask of 0.0.0.31.
How many /26 subnets fit in a /24?
Four. Each /26 has 64 addresses (62 usable), and 4 × 64 = 256.