No tool matches “”

Try a format (“webp”, “mp3”) or a verb (“merge”, “compress”).

Loading index

↵to open

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.

IPv4 blocks and their usable host counts
PrefixMaskHost bitsAddressesUsable hosts
/24255.255.255.08256254
/25255.255.255.1287128126
/26255.255.255.19266462
/27255.255.255.22453230
/28255.255.255.24041614
/29255.255.255.248386

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.

Frequently asked questions

What does the number after the slash mean in a CIDR block?
It is the prefix length: the number of leading bits that identify the network. A /24 uses 24 network bits and leaves eight host bits, which is 256 addresses before the network and broadcast addresses are removed.
Why are two addresses per IPv4 subnet unusable?
The lowest address is the network address and the highest is the broadcast address, and neither is assigned to an ordinary device. For that reason the usable host count is 2^h minus 2 for all subnets except /31 and /32.
How many usable hosts does a /24 or a /30 have?
A /24 has 254 usable host addresses (256 minus two), a /25 has 126 and a /30 has two, which is why /30 is typical for point-to-point links. A /31 has two usable addresses under RFC 3021 and a /32 has one.
When should I use /31 or /32?
Use /31 on point-to-point links where both addresses are endpoints, as RFC 3021 describes, and /32 for a single host route such as a loopback or a cloud route to one machine. Both cases avoid the network and broadcast reservation.
How do I check whether an address belongs to a subnet?
Apply the mask to the address with a bitwise AND: if the result equals the network address of the block, the address is inside it. Comparing the first prefix bits of both addresses is the same test written in binary.
How does IPv6 change the arithmetic?
Addresses are 128 bits instead of 32, and the same CIDR notation applies. Subnets are typically /64, there is no broadcast address to subtract, and address space is large enough that subnetting for scarcity is not the usual reason to split a network.

Tools for this job

All Network Tools