gotinfo.net by VARØ Industries

How to Read CIDR Notation and Calculate a Subnet by Hand

GotInfo guides  |  VARØ Industries

A calculator gives you the answer instantly, but knowing the method lets you sanity-check a firewall rule or a cloud network plan in your head. This guide covers the arithmetic with worked examples you can check against the GotInfo subnet calculator.

What the slash number means

An IPv4 address is 32 bits. CIDR notation such as 192.168.10.0/24 says that the first 24 bits are the network part, shared by every address in the block, and the remaining 8 bits are the host part, which varies. The number of addresses in the block is therefore 2 raised to the number of host bits:

addresses = 2(32 − prefix)

So a /24 has 28 = 256 addresses, a /26 has 26 = 64, and a /30 has 22 = 4. In a normal IPv4 subnet the first address is the network address and the last is the broadcast address, so the usable host count is two less.

Prefix, mask and wildcard

The same information can be written as a subnet mask: 32 bits with ones for the network part and zeros for the host part. A wildcard mask, used in some router access lists, is the inverse. This table covers the prefixes you meet most often.

PrefixSubnet maskWildcardAddressesUsable hosts
/8255.0.0.00.255.255.25516,777,21616,777,214
/16255.255.0.00.0.255.25565,53665,534
/22255.255.252.00.0.3.2551,0241,022
/23255.255.254.00.0.1.255512510
/24255.255.255.00.0.0.255256254
/25255.255.255.1280.0.0.127128126
/26255.255.255.1920.0.0.636462
/27255.255.255.2240.0.0.313230
/28255.255.255.2400.0.0.151614
/29255.255.255.2480.0.0.786
/30255.255.255.2520.0.0.342
/31255.255.255.2540.0.0.122 (point-to-point links, RFC 3021)
/32255.255.255.2550.0.0.011 (a single host)

The mask octets only ever take nine values: 0, 128, 192, 224, 240, 248, 252, 254 and 255. Each one is 256 minus a power of two, which is the key to the shortcut below.

The block-size method

You do not need to convert everything to binary. For any address and prefix:

  1. Find the interesting octet. This is the octet where the mask is neither 255 nor 0. For a /26 it is the fourth octet (mask 192). For a /22 it is the third (mask 252).
  2. Work out the block size. Block size = 256 minus the mask value in that octet. For 192 that is 64; for 252 it is 4.
  3. Find the network address. Round the address's value in the interesting octet down to the nearest multiple of the block size. Octets to the right become 0.
  4. Find the broadcast address. Add the block size to the network value, subtract 1, and set octets to the right to 255.
  5. Host range. Network address plus one to broadcast address minus one.

Worked example 1: 192.168.10.77/26

Worked example 2: is 10.20.4.1 inside 10.20.0.0/22?

This is the kind of check that matters when a firewall rule or security group "should" allow a host and does not.

Worked example 3: splitting a /24 for four VLANs

You have 192.168.10.0/24 and need four networks of at least 50 hosts each. A /26 gives 62 usable hosts, and a /24 divides into four of them, because each extra prefix bit halves the block:

SubnetHostsBroadcast
192.168.10.0/26.1 to .62.63
192.168.10.64/26.65 to .126.127
192.168.10.128/26.129 to .190.191
192.168.10.192/26.193 to .254.255

If one VLAN needed 100 hosts, you could use a /25 for it (126 hosts) and split the other half into two /26 networks. Subnets of different sizes in the same block are fine as long as each starts on a multiple of its own block size.

Worked example 4: summarizing routes

Aggregation goes the other way. 198.51.100.0/25, 198.51.100.128/26 and 198.51.100.192/26 together cover every address from .0 to .255, so they collapse into one entry: 198.51.100.0/24. Blocks only combine when they are adjacent, the same size at each step, and the result starts on the right boundary. 203.0.113.0/26 and 203.0.113.64/26 combine into 203.0.113.0/25, but 203.0.113.160/27 sits apart and has to stay as its own entry. The aggregation tool on the subnet calculator does this for a whole list at once.

Common mistakes

IPv6 is simpler

The same arithmetic applies to 128-bit addresses, but the conventions remove most of the planning. Each LAN segment is a /64, regardless of how many devices it has, and there is no broadcast address. A site with a /48 has 216 = 65,536 possible /64 networks, and a /56 has 28 = 256. Subnetting usually means numbering the 16 or 8 bits between the site prefix and the /64 boundary, for example giving each building or VLAN its own value in the fourth group. See IPv4 vs IPv6 for how the address halves fit together.

Check your working: open the GotInfo subnet calculator, which shows the network, broadcast, host range and a binary view for any IPv4 or IPv6 CIDR.

Related guides