What CIDR notation means
CIDR notation writes a network as an address followed by a prefix length. In 192.168.1.0/24, the first 24 bits identify the network and the remaining 8 bits number the hosts inside it, so the block holds 256 addresses.
For IPv4, a /n block contains 2 to the power of (32 minus n) addresses. Each step up in prefix length halves the block and each step down doubles it, so a smaller number means a larger network.
CIDR (Classless Inter-Domain Routing) replaced the old address classes in 1993. Class A, B and C networks had fixed sizes of /8, /16 and /24, which wasted space. CIDR allows a prefix of any length, and routers can combine neighboring blocks into one route.
Prefix lengths, subnet masks and address counts
A subnet mask is the same information written as an address: network bits are 1s and host bits are 0s. A /24 is 255.255.255.0, and a /26 is 255.255.255.192 because its last byte, 11000000, equals 192.
In most subnets the usable host count is two less than the total, for reasons explained in the next section.
Prefix Subnet mask Addresses Usable hosts
/8 255.0.0.0 16,777,216 16,777,214
/16 255.255.0.0 65,536 65,534
/20 255.255.240.0 4,096 4,094
/24 255.255.255.0 256 254
/26 255.255.255.192 64 62
/28 255.255.255.240 16 14
/30 255.255.255.252 4 2
/31 255.255.255.254 2 2 (point-to-point links)
/32 255.255.255.255 1 1 (a single host)Network and broadcast addresses in IPv4
In an IPv4 subnet, the first address, with all host bits set to 0, is the network address. The last, with all host bits set to 1, is the broadcast address, which reaches every device on the subnet. Neither is assigned to a device, which is why a /24 has 254 usable addresses rather than 256.
There are two common exceptions. A /31 gives both of its addresses to the two ends of a point-to-point link (RFC 3021), and a /32 names a single host. Cloud providers often reserve a few more addresses in each subnet for their own services, so check the provider's documentation.
Devices use the mask to decide whether a destination is local. They apply a bitwise AND to the destination address and the mask and compare the result with their own network address. If it matches, they deliver directly on the local network; otherwise they send the packet to the default gateway.
Address: 192.168.1.50 11000000.10101000.00000001.00110010
Mask: 255.255.255.0 11111111.11111111.11111111.00000000
AND: 192.168.1.0 11000000.10101000.00000001.00000000Worked examples: a /24, four /26 subnets and a /16
Start with 192.168.10.0/24. Its mask is 255.255.255.0 and it covers 192.168.10.0 to 192.168.10.255, with network address .0, broadcast address .255 and 254 usable hosts from .1 to .254.
To split it into four subnets, take 2 bits from the host part, making each subnet a /26. The block size is 256 minus 192, or 64, so the subnets start at multiples of 64, as the table below shows.
To check whether 192.168.10.77 is in 192.168.10.64/26, see whether 77 falls between 64 and 127. It does, so the address is in that subnet and its broadcast address is 192.168.10.127.
A /16 works the same way at a larger scale. 172.16.0.0/16 has the mask 255.255.0.0 and covers 172.16.0.0 to 172.16.255.255: 65,536 addresses, or room for 256 separate /24 subnets.
192.168.10.0/24 split into four /26 subnets (mask 255.255.255.192)
Subnet Usable hosts Broadcast
192.168.10.0/26 192.168.10.1 to 192.168.10.62 192.168.10.63
192.168.10.64/26 192.168.10.65 to 192.168.10.126 192.168.10.127
192.168.10.128/26 192.168.10.129 to 192.168.10.190 192.168.10.191
192.168.10.192/26 192.168.10.193 to 192.168.10.254 192.168.10.255IPv6 subnets: why /64 is the standard size
IPv6 uses the same prefix notation over 128 bits. A local network is almost always a /64: the first 64 bits are the network prefix and the last 64 identify the interface. SLAAC, the way most IPv6 devices configure their own addresses, needs a /64 to work.
A /64 holds 2 to the power of 64 addresses, so nobody counts hosts in IPv6; you count subnets instead. A site that receives a /48 can make 65,536 /64 subnets, and a /56 gives 256.
With 2001:db8:abcd::/48, the fourth group numbers the subnet: 2001:db8:abcd:1::/64, 2001:db8:abcd:2::/64 and so on up to 2001:db8:abcd:ffff::/64. IPv6 has no broadcast, so there is no broadcast address to set aside.
Common subnetting mistakes
Most subnetting problems show up later, when networks are connected or need to grow.
- Overlapping ranges break routing once two networks are joined, such as an office and a cloud network over a VPN. Many home routers default to 192.168.0.0/24 or 192.168.1.0/24, so a company network that remote staff reach over a VPN should avoid those ranges.
- Writing a host address where a network is expected confuses tools. 192.168.1.10/24 describes a host in the 192.168.1.0/24 network, and many tools reject it or round it down when they expect a network.
- Sizing subnets with no room to grow usually means renumbering later, so leave space between allocations.
- Counting usable hosts without subtracting the network, broadcast and any provider-reserved addresses leaves a subnet short.