Home / Guides / Subnetting and CIDR explained with practical examples
Subnetting and CIDR explained with practical examples
Every device on a network has an IP address, and networks are divided into groups called subnets. Subnetting decides which addresses belong together, which can talk directly to each other and where traffic has to go through a router. It sounds abstract, but it comes down to a little binary arithmetic.
IPv4 addresses are 32 bits
An IPv4 address such as 192.168.1.10 is a 32-bit number written as four bytes (octets) in decimal:
192 .168 .1 .10
11000000 .10101000 .00000001 .00001010
A subnet splits those 32 bits into two parts:
- the first bits identify the network,
- the remaining bits identify the host inside that network.
The netmask and the prefix
The netmask marks which bits belong to the network. Where the mask has a 1, the bit is part of the network. Where it has a 0, it is part of the host.
Address: 192.168.1.10 11000000.10101000.00000001.00001010
Netmask: 255.255.255.0 11111111.11111111.11111111.00000000
Network: 192.168.1.0 11000000.10101000.00000001.00000000
Writing the mask in full is clumsy, so we count the 1 bits and write it as a prefix length. 255.255.255.0 has 24 ones, so the network is written 192.168.1.0/24. This is CIDR notation (Classless Inter-Domain Routing, introduced in 1993 to replace the old fixed class A, B and C sizes).
How many addresses are in a subnet
A prefix of /n leaves 32 โ n bits for hosts, so the block has 2^(32 โ n) addresses.
| Prefix | Netmask | Addresses | Usable hosts |
|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,216 | 16,777,214 |
| /16 | 255.255.0.0 | 65,536 | 65,534 |
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 6 |
| /30 | 255.255.255.252 | 4 | 2 |
| /31 | 255.255.255.254 | 2 | 2 (special case) |
| /32 | 255.255.255.255 | 1 | 1 (single host) |
Usable hosts are two fewer than the total, because two addresses are reserved in each ordinary subnet:
- the network address, the first one (all host bits 0), which names the subnet,
- the broadcast address, the last one (all host bits 1), which reaches every host in it.
Two special cases
- /31 (RFC 3021) is used on point-to-point links between two routers. Both addresses are usable, and there is no broadcast address.
- /32 identifies one single address, for example a loopback or a host route.
A worked example
Which network does 172.16.37.200/20 belong to?
- A /20 has 20 network bits, so the host part is 12 bits (4096 addresses).
- The mask is
255.255.240.0. The interesting octet is the third:240 = 11110000, which gives blocks of 16 in the third octet (256 โ 240 = 16). - The third octet of the address is 37. The multiple of 16 at or below 37 is 32. So the network starts at
172.16.32.0. - The block lasts 16 values in the third octet, so it ends at
172.16.47.255(the broadcast address). - The usable range is
172.16.32.1to172.16.47.254, which is 4094 hosts.
You can confirm this instantly with the Subnet (CIDR) Calculator.
Splitting a network
Suppose you have 192.168.1.0/24 and want four equal subnets. Adding 2 bits to the prefix (2ยฒ = 4) gives /26 blocks of 64 addresses:
192.168.1.0/26 hosts .1 to .62 broadcast .63
192.168.1.64/26 hosts .65 to .126 broadcast .127
192.168.1.128/26 hosts .129 to .190 broadcast .191
192.168.1.192/26 hosts .193 to .254 broadcast .255
The calculator can split any block for you and list the results.
Private and special ranges
These ranges are reserved and are not routed on the public internet:
| Range | Use |
|---|---|
| 10.0.0.0/8 | Private networks |
| 172.16.0.0/12 | Private networks |
| 192.168.0.0/16 | Private networks, typical at home |
| 100.64.0.0/10 | Carrier-grade NAT (shared address space) |
| 127.0.0.0/8 | Loopback (the device itself) |
| 169.254.0.0/16 | Link-local (self-assigned when DHCP fails) |
Your home devices have addresses from a private range, and share the public address you can see with What Is My IP. The router translates between them with NAT. For more on this, read what an IP address is.
IPv6 subnetting is simpler
IPv6 addresses are 128 bits, so the logic is the same with bigger numbers, and there is no broadcast address.
- A single network (LAN) normally gets a /64, which is 2โถโด addresses.
- Internet providers typically give customers a /56 or /48, which contain 256 or 65,536 /64 networks.
- A /128 is a single address.
Because networks are so large, you split IPv6 by choosing which /64 goes where, not by saving addresses.
The wildcard mask
Firewalls and routers sometimes ask for a wildcard mask, the inverse of the netmask. For 255.255.255.0 it is 0.0.0.255. Where the wildcard has a 0 the bit must match, and where it has a 1 anything goes.
Planning an address scheme
- Leave room to grow. Do not size a subnet for todayโs devices only. Plan for double.
- Align by function. Servers, users, guests, printers and cameras in separate subnets make rules and troubleshooting easier.
- Avoid overlaps. Two networks using
192.168.1.0/24cannot be joined without renumbering, and VPNs fail when ranges overlap. Pick less common ranges, such as10.x.y.0/24, for places you might connect. - Document it. A table of subnets, purposes and owners saves hours later.
The Subnet (CIDR) Calculator also tells you whether a given address belongs to a block, which is a quick way to test a firewall rule or a route.