Skip to content
IP Address Today

Networking

CIDR and subnetting without the mental arithmetic

By 8 min read

Subnetting has a reputation for being hard. It is not hard — it is binary arithmetic wearing a disguise, and the disguise is dotted-decimal notation, which hides the only thing that matters.

The notation is the problem

An IPv4 address is 32 bits. We write it as four decimal numbers because that is easier to read than 32 ones and zeros. That convenience is also what makes subnetting look mysterious, because subnetting operates on bits and the decimal form hides where the bits are.

192.168.10.0/24 means: the first 24 bits identify the network, the remaining 8 identify a host within it.

192.168.10.0/24

11000000.10101000.00001010.00000000
|--------network (24)--------|-host-|

That is the entire concept. Everything else is consequence.

What the prefix length gives you

The host bits determine the size of the block:

PrefixHost bitsAddressesCommon use
/3201A single host
/3112Point-to-point links
/3024Small point-to-point
/2938Tiny subnet
/248256Classic "class C"
/161665,536Large private network
/82416,777,216Very large allocation

Each bit you give to the network halves the block. Each bit you give to hosts doubles it. That is the whole relationship, and it is why the numbers are always powers of two.

Useful shortcut: the number of addresses is 2^(32 − prefix). A /26 has 2^6 = 64 addresses. A /22 has 2^10 = 1,024.

Network, broadcast, and usable

Within a block, two addresses are traditionally special:

  • The network address — all host bits zero
  • The broadcast address — all host bits one

For 192.168.10.0/24 those are 192.168.10.0 and 192.168.10.255, leaving 254 usable host addresses.

The exception worth knowing: /31 has no broadcast. RFC 3021 allows both addresses in a /31 to be used, which is why point-to-point links use them — two addresses, both usable, no waste.

The mask is the same information

A subnet mask is the prefix length written as a dotted quad: ones for network bits, zeros for host bits.

/24  →  255.255.255.0
/26  →  255.255.255.192
/30  →  255.255.255.252

255.255.255.192 is 11111111.11111111.11111111.11000000 — 26 ones. The mask and the prefix carry identical information; the mask is the older way of writing it.

The wildcard mask is the mask inverted (0.0.0.63 for a /26). It appears in ACLs and routing configuration, and it exists because some equipment matches on the bits that may vary rather than the bits that must match.

Where the confusion usually comes from

Host bits left set. 192.168.10.5/24 does not describe a block starting at .5. The /24 means only the first 24 bits are significant, so the host bits are masked off and the block is 192.168.10.0/24. Any tool that does not do this masking is wrong.

Subnets are not always on octet boundaries. /24, /16 and /8 line up neatly with the dots, which is why they feel easy. A /26 splits an octet, so the block boundaries are 0, 64, 128, 192 — and this is exactly where dotted-decimal stops helping and you have to think in bits.

Overlap is not obvious by eye. 10.0.0.0/16 contains 10.0.5.0/24. Nothing in the notation makes that visible, which is why range checks belong in code rather than in your head.

Splitting a block

To divide a /24 into four equal subnets: you need four pieces, four is 2², so borrow 2 bits from the host portion. /24 + 2 = /26.

192.168.10.0/26     .0   – .63
192.168.10.64/26    .64  – .127
192.168.10.128/26   .128 – .191
192.168.10.192/26   .192 – .255

The increment is 64, which is the block size — and the block size is always the increment. Once you see that, splitting is arithmetic rather than a puzzle.

IPv6 is the same idea, easier

The concept is identical; only the numbers change. Prefixes go to /128, and the common allocation boundaries are /48, /56 and /64.

It is arguably simpler than IPv4, because the addresses are so plentiful that you rarely need to squeeze a block to fit. A /64 per network is the norm, and you stop optimising.


If you want the arithmetic done for you, the subnet calculator gives network and broadcast addresses, masks, wildcard masks and host counts for any block, and the CIDR to IP range converter goes both ways — including collapsing an arbitrary range into the smallest set of CIDR blocks. There is also a subnet mask cheat sheet if you just need the table. All of them run in your browser; nothing is sent anywhere.

All posts · RSS

Build this into your app

Same data as this page, as JSON. 45 requests a minute with no key, 10,000 a month free with one.

curl https://api.ipaddresstoday.com/api/v1/ip