Home › Guides › CIDR and Subnetting

CIDR Notation and Subnetting, with a Cheat Sheet

CIDR notation writes an IP network as an address plus a slash and a number, like 192.168.1.0/24. The number is how many bits, counted from the left, identify the network; the rest identify hosts inside it. Once that clicks, subnet masks, host counts and network ranges all follow from simple powers of two. This guide has a cheat sheet, a worked example done by hand, and the gotchas from cloud providers. Check any of it in the IP subnet calculator.

Prefix length and host count

An IPv4 address has 32 bits. A /24 uses 24 for the network and leaves 8 for hosts, so it contains 28 = 256 addresses. In a normal subnet, the first is the network address and the last is the broadcast address, so 254 can be given to hosts.

CIDRSubnet maskAddressesUsable hosts
/8255.0.0.016,777,21616,777,214
/16255.255.0.065,53665,534
/20255.255.240.04,0964,094
/22255.255.252.01,0241,022
/23255.255.254.0512510
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/29255.255.255.24886
/30255.255.255.25242
/31255.255.255.25422 (point-to-point links, RFC 3021)
/32255.255.255.25511 (a single host)

Each step of one bit doubles or halves the size. A /23 is two /24s; a /24 splits into two /25s or four /26s.

Worked example: which subnet is 192.168.10.77/26 in?

  1. A /26 has 232−26 = 64 addresses, so subnets in the last octet start at multiples of 64: 0, 64, 128, 192.
  2. 77 falls between 64 and 127.
  3. Network address: 192.168.10.64. Broadcast: 192.168.10.127.
  4. Usable hosts: 192.168.10.65 to 192.168.10.126, which is 62 addresses.
  5. Mask: 255.255.255.192, because 26 bits set means three full octets (255) plus 2 bits in the last octet (128 + 64 = 192).

The shortcut works for any prefix: find the block size (256 minus the mask value in the octet that isn't 0 or 255), then find the multiple of the block size at or below the address.

Splitting a network

To split 10.0.0.0/24 into four equal subnets, borrow 2 bits (22 = 4), giving four /26s:

10.0.0.0/26     hosts .1 – .62
10.0.0.64/26    hosts .65 – .126
10.0.0.128/26   hosts .129 – .190
10.0.0.192/26   hosts .193 – .254

Subnets don't have to be the same size, but each one must start on a multiple of its own size. A /25 can start at .0 or .128, never at .64.

Private address ranges

RFC 1918 sets aside three ranges for private networks that aren't routed on the public internet:

  • 10.0.0.0/8 (10.0.0.0 – 10.255.255.255)
  • 172.16.0.0/12 (172.16.0.0 – 172.31.255.255, not all of 172.x)
  • 192.168.0.0/16 (192.168.0.0 – 192.168.255.255)

Pick ranges that won't overlap with networks you may need to connect later, such as an office VPN or another cloud VPC. Overlapping ranges are painful to fix after the fact.

Cloud gotchas

  • AWS and Azure reserve 5 addresses in every subnet, not 2: the network address, the next three, and the last. A /28 there gives 11 usable addresses, not 14.
  • Plan the VPC big and the subnets small. A /16 VPC split into /24 subnets leaves room to grow; resizing later usually means rebuilding.
  • Security group and firewall rules use CIDR too. 0.0.0.0/0 means every IPv4 address. 203.0.113.5/32 means exactly one.

IPv6 in one paragraph

IPv6 addresses have 128 bits and use the same prefix idea, but the sizes are so large that nobody counts hosts. The standard subnet for a LAN is a /64, which many features such as SLAAC address autoconfiguration expect. Sites commonly get a /48 or /56 and split it into /64s. There is no broadcast address. The IPv6 subnet calculator shows the range and the compressed and expanded forms.

Related tools

References