Practical Guide to CIDR Notation & IPv4 Subnetting
Whether you are carving up a cloud VPC in AWS or Azure, writing firewall allowlists, or troubleshooting why two hosts on the same office switch cannot ping each other, CIDR subnetting is the core skill that makes IP addressing predictable.
1. What the Slash Number in CIDR Actually Means
Classless Inter-Domain Routing (CIDR) replaced rigid 1980s Class A/B/C boundaries with a flexible prefix length written after a slash, such as 10.20.4.0/24. Because an IPv4 address has 32 bits in total:
- The prefix length (
/24) specifies how many leading bits identify the network. - The remaining bits (
32 - 24 = 8) identify individual hosts inside that network. - Total addresses in the subnet always equal
2(32 - prefix).
In standard subnets (/0 through /30), two addresses are reserved: the very first address (all host bits = 0) is the Network ID, and the very last address (all host bits = 1) is the Broadcast Address. That leaves 2(32 - prefix) - 2 usable host addresses.
2. Fast Mental Math: The "Magic Block Size" Trick
You do not need to write out 32 binary digits every time you inspect a subnet between /24 and /30. Subtract the mask's interesting octet from 256 to get the exact block size:
Example: 192.168.50.140/26
1. /26 has 26 network bits → 24 bits in first 3 octets + 2 bits in 4th octet.
2. Mask's 4th octet = 128 + 64 = 192 (Subnet mask: 255.255.255.192)
3. Block size = 256 - 192 = 64
4. Valid /26 boundaries start at multiples of 64: 0, 64, 128, 192
5. 140 falls inside [128 .. 191]:
- Network ID: 192.168.50.128
- First usable: 192.168.50.129
- Last usable: 192.168.50.190
- Broadcast: 192.168.50.191
The exact same block-size rule works in the third octet for prefixes /16 through /23 (for instance, a /22 has a third-octet mask of 252, giving a block size of 256 - 252 = 4 third-octet increments, or 1,024 total IPs).
3. Worked Example: Planning a Cloud VPC with VLSM
Suppose your team is allocated 10.20.0.0/22 (1,024 total IPs spanning 10.20.0.0 through 10.20.3.255) and needs to deploy a three-tier web application across two availability zones using Variable Length Subnet Masking (VLSM):
| Tier / Subnet Role | CIDR Block | Address Range | Total IPs | Why This Size? |
|---|---|---|---|---|
| Public Load Balancers (AZ-a) | 10.20.0.0/26 | 10.20.0.0 – .63 | 64 | Only ALBs and NAT gateways sit in public subnets |
| Public Load Balancers (AZ-b) | 10.20.0.64/26 | 10.20.0.64 – .127 | 64 | Mirrored public subnet in second AZ |
| Database Tier (AZ-a) | 10.20.0.128/26 | 10.20.0.128 – .191 | 64 | Isolated private DB instances and replicas |
| Database Tier (AZ-b) | 10.20.0.192/26 | 10.20.0.192 – .255 | 64 | Multi-AZ standby database subnet |
| App / Kubernetes Tier (AZ-a) | 10.20.1.0/24 | 10.20.1.0 – 10.20.1.255 | 256 | Room for autoscaling pods and containers |
| App / Kubernetes Tier (AZ-b) | 10.20.2.0/24 | 10.20.2.0 – 10.20.2.255 | 256 | Mirrored private compute capacity |
| Reserved Future Growth | 10.20.3.0/24 | 10.20.3.0 – 10.20.3.255 | 256 | Unallocated buffer for new services or peering |
/28 subnet in the cloud!
4. Special Prefix Cases: /31 and /32
/31Point-to-Point Links (RFC 3021): Traditionally, connecting two routers required a/30(4 IPs, wasting 2). RFC 3021 allows point-to-point router links to use a/31where both addresses act as valid host interfaces with no broadcast address — cutting transit IP consumption in half./32Host Routes: All 32 bits are fixed, matching exactly one IPv4 address. Essential for firewall allowlists (e.g., permitting SSH only from your office static IP203.0.113.10/32), BGP loopback interfaces, and VPN host routes.
5. Wildcard Masks (Inverse Masks) for Router ACLs
Cisco IOS access control lists (ACLs) and OSPF area statements often require a wildcard mask instead of a subnet mask. A wildcard mask is simply the bitwise inverse of the subnet mask (subtract each octet from 255): where a subnet mask uses 1 to lock a bit, a wildcard mask uses 0 to match and 1 to ignore. For example, subnet mask 255.255.255.192 (/26) has wildcard mask 0.0.0.63.
6. Three Classic Subnetting Mistakes to Avoid
- Misaligned CIDR boundaries: Writing
192.168.1.100/26is not a valid network boundary because 100 is not a multiple of 64; routers normalize it to192.168.1.64/26. - Overlapping VPC/VPN ranges: Using default
192.168.1.0/24or10.0.0.0/16in every environment causes painful routing conflicts the moment you need site-to-site VPN or VPC peering. Pick distinct, non-overlapping slices of10.0.0.0/8from day one. - Forgetting IPv6's
/64rule: In IPv6, LAN subnets should almost always be/64so Stateless Address Autoconfiguration (SLAAC) functions properly. Do not subnet IPv6 LANs smaller than/64just to "save addresses."