GONDAL AI / BLOG

How to Calculate a Subnet: CIDR, Masks and Host Ranges, Worked by Hand

To calculate a subnet, you take an IP address and a CIDR prefix, turn the prefix into a mask, and let the mask split the address into the network it belongs to and the host range inside it. It is four short steps of arithmetic — no binary conversion marathon — and this post works one real address end to end using the exact rules our free Subnet Calculator runs, so you can check every number yourself.

How to calculate a subnet — this site's own social image, next to the worked 10.20.30.40/26 subnet calculation below
The worked example below takes 10.20.30.40/26 apart step by step: network 10.20.30.0, broadcast 10.20.30.63, 62 usable hosts.

How to calculate a subnet in four steps

  1. Prefix to mask. The CIDR prefix counts the network bits. /26 means the first 26 of the address's 32 bits are the network, written as a mask that is 255.255.255.192 — three full 255 octets (24 bits) plus 192, which is the top two bits of the last octet.
  2. Count the addresses. The bits left over name the hosts: 32 − 26 = 6 host bits, so the block holds 26 = 64 addresses.
  3. Find the network address. Keep only the bits the mask covers. In the last octet, 40 with only its top two bits kept is 0 — so the network is 10.20.30.0, and our address 10.20.30.40 sits 40 addresses into its own block.
  4. Find the broadcast and the range. Set every host bit to 1 for the broadcast: last octet 63, so 10.20.30.63. The usable hosts are everything between: 10.20.30.1 – 10.20.30.62 — 64 addresses minus the network and broadcast = 62 usable hosts.

That is the whole method, and it is exactly what our free Subnet Calculator does when you type an address in: it builds the mask from the prefix with a bit shift, ANDs it with the address for the network, flips the mask's bits for the broadcast, and counts 2(32 − prefix) addresses. Type 10.20.30.40 and /26 into it and you will get the four numbers above — plus the wildcard mask, 0.0.0.63, which is just the mask with every bit flipped.

The halving table: every step up doubles or halves the block

Once the method clicks, most subnet questions are answered by one pattern: each +1 on the prefix halves the block, each −1 doubles it. These are the sizes around the range people actually meet, all from the same 2(32 − prefix) rule:

  • /23 — 512 addresses, 510 usable
  • /24 — 256 addresses, 254 usable (the classic home network: 192.168.1.1 – 192.168.1.254)
  • /25 — 128 addresses, 126 usable
  • /26 — 64 addresses, 62 usable (the worked example)
  • /27 — 32 addresses, 30 usable
  • /28 — 16 addresses, 14 usable
  • /29 — 8 addresses, 6 usable
  • /30 — 4 addresses, 2 usable

Splitting is the same table read backwards: carve a /24 into four equal subnets and each piece is a /26 — networks at .0, .64, .128 and .192, 62 usable hosts apiece. Need about 50 hosts? A /26 (62) fits; the next size down, /27 (30), does not. That one comparison — smallest block that fits, counted from the table — is 90% of real-world subnetting.

CIDR or subnet mask — saying the same thing two ways

/26 and 255.255.255.192 are the same fact in two notations: the prefix counts the 1-bits, the mask writes them out. Our calculator keeps the two fields in sync as you type, and it will refuse a mask whose bits are not contiguous — all 1s, then all 0s — because a mask like 255.255.255.193 is not a sloppy mask, it is not a mask at all. The third notation, the wildcard mask (0.0.0.63 for a /26), is the mask flipped bit for bit; Cisco access lists and OSPF statements are written with it, where a 0 bit means "must match" and a 1 bit means "don't care".

The two edge cases: /31 and /32

The "minus two" rule breaks at the bottom of the table. A /31 holds exactly two addresses, and under the classic rules both are spent — one network, one broadcast, nothing usable — which is why our calculator reports "none under classic rules" for it. In practice /31s are used on point-to-point links under RFC 3021, where both addresses carry traffic; a /30 is the safe choice when a device insists on the classic rules. A /32 is simpler: one address, one host, no range at all — the notation for "exactly this machine".

One last thing the calculator tells you for free: whether the address is private, loopback or public. 10.20.30.40 is private (the 10.0.0.0/8 block, one of the RFC 1918 ranges), which is why it makes a safe worked example — it belongs to no one on the public internet. For the maths behind a very different everyday number, see our explainer on how long a password should be.