fundamentals · 7 min read
Subnetting and CIDR explained
Subnetting splits one block of IP addresses into smaller ones. CIDR is the notation that records where the split happens: the number after the slash in 192.168.10.0/24 is the count of leading bits that identify the network.
Read that number as a mask and the rest becomes arithmetic: which addresses belong to the block, which one is reserved for the network itself, which one is the broadcast address, and how many hosts actually remain for devices.
An IPv4 address is a 32-bit number
Every IPv4 address is a 32-bit integer written as four decimal octets, and that is why subnet math starts with binary. 192.168.10.42 is 11000000 10101000 00001010 00101010 in binary; the dotted form is a convenience for people, not a requirement of the protocol.
A mask is the same length as the address and marks which bits belong to the network and which belong to the host. A bit set to 1 means the position is part of the network portion; a 0 means the position can vary between hosts in that block.
- Network bits: fixed for every address in the block and used to identify the subnet.
- Host bits: vary from device to device, and their count determines how many addresses the block holds.
- Dotted-decimal masks are just the binary mask converted back to octets: 255.255.255.0 is 24 ones followed by eight zeros in the address size most commonly used here.
Prefix length and the dotted-decimal mask
A /24 means the first 24 bits are network bits, so the mask is 255.255.255.0. The four octets are eight bits each: 24 network bits fill three octets, leaving the last octet for hosts.
A mask does not have to land on an octet boundary. /26 sets 26 bits to 1, which is 255.255.255.192: the first three octets are full, and the last octet contributes two more network bits, leaving six host bits. Any prefix from /0 to /32 is valid notation, though only a few are common on office networks.
| Prefix | Mask | Host bits | Addresses | Usable hosts |
|---|---|---|---|---|
| /24 | 255.255.255.0 | 8 | 256 | 254 |
| /25 | 255.255.255.128 | 7 | 128 | 126 |
| /26 | 255.255.255.192 | 6 | 64 | 62 |
| /27 | 255.255.255.224 | 5 | 32 | 30 |
| /28 | 255.255.255.240 | 4 | 16 | 14 |
| /29 | 255.255.255.248 | 3 | 8 | 6 |
Network and broadcast addresses
Within any IPv4 block, the lowest address has all host bits set to 0 and is the network address; it identifies the subnet itself and is not assigned to a device. The highest address has all host bits set to 1 and is the directed broadcast address for that block.
That convention is why the usable-host formula is 2^h minus 2 for ordinary subnets: two addresses in every block are reserved. For a /24, 256 addresses minus two leaves 254; for a /29, eight addresses minus two leaves six.
Worked example: 192.168.10.42/24
The address is in 192.168.10.0/24, so the last octet is the host portion and the mask is 255.255.255.0. The network address is 192.168.10.0 and the broadcast address is 192.168.10.255.
The assignable range runs from 192.168.10.1 to 192.168.10.254, which is 254 usable hosts. A second subnet in the same design would usually start at 192.168.11.0/24, and routers on the network would need a route for each block.
- Network address: 192.168.10.0
- First usable host: 192.168.10.1
- Last usable host: 192.168.10.254
- Broadcast address: 192.168.10.255
Worked example: 10.0.0.5 to 10.0.0.10
A range that does not start and end on a CIDR boundary cannot be described by one prefix. 10.0.0.5 is odd, so it must be a /32; 10.0.0.6 and 10.0.0.7 pair into a /31; 10.0.0.8 and 10.0.0.9 pair into another /31; 10.0.0.10 is again a /32.
Expressed compactly, the range is 10.0.0.5/32, 10.0.0.6/31, 10.0.0.8/31 and 10.0.0.10/32. A firewall rule that needs exactly this span has to list those four prefixes, or accept the nearest enclosing /28, 10.0.0.0/28, and take ten extra addresses that were not in the request.
- 10.0.0.5/32: one address
- 10.0.0.6/31: two addresses, 10.0.0.6 and 10.0.0.7
- 10.0.0.8/31: two addresses, 10.0.0.8 and 10.0.0.9
- 10.0.0.10/32: one address
Special cases: /31 and /32
Two prefixes break the two-reserved-addresses habit. RFC 3021 defines /31 for point-to-point links: the two addresses in the block are used as the two ends of the link, and there is no broadcast address, so both are usable.
/32 describes exactly one address. It appears in host routes, in allow lists and in loopback addresses such as 127.0.0.1. In cloud routing tables, a /32 is the normal way to route traffic to a single machine.
Aggregation and what changes in IPv6
Contiguous, aligned blocks can be merged back into a shorter prefix. 10.0.0.0/24 and 10.0.1.0/24 are adjacent and aligned on an even /23 boundary, so both can be advertised as 10.0.0.0/23. If the pair started at an odd /24, aggregation would have to wait until the neighboring block was included.
IPv6 uses the same prefix-length notation on a 128-bit address, so the mental model carries over directly. What changes is scale and convention: a typical LAN subnet is a /64, networks are normally not subdivided because addresses are plentiful, and there is no broadcast address at all. A /64 holds 2^64 addresses, far more than the 254 of the most common IPv4 subnet.

