Demystifying CIDR & IP Subnetting: A Practical Guide for Developers
Whether configuring an AWS VPC security group, establishing Kubernetes Pod CIDR boundaries, or auditing firewall rules, developers encounter IP addresses with slash notation (like 10.0.0.0/16 or 192.168.1.0/24) every day.
To many engineers, subnet math feels unintuitive. In this guide, we break down the 32-bit architecture of IPv4, explain how binary bitwise AND operations partition networks, and provide clear formulas to calculate usable host ranges.
1. The Anatomy of an IPv4 Address
An IPv4 address is simply a 32-bit unsigned integer. To make it readable, humans write it as four 8-bit octets separated by dots (Dotted Decimal Notation):
2. What is CIDR Notation?
Historically, the Internet assigned addresses using rigid "Classes" (Class A, B, and C), which led to massive wastage of IPv4 address space. In 1993, Classless Inter-Domain Routing (CIDR) was introduced (RFC 1519).
The number following the slash (e.g. /24) indicates the prefix length: exactly how many leading bits belong to the Network ID, with the remaining bits belonging to individual Hosts.
| CIDR Prefix | Subnet Mask | Total Addresses | Usable Hosts |
|---|---|---|---|
/32 |
255.255.255.255 |
1 | 1 (Single Host / Loopback) |
/28 |
255.255.255.240 |
16 | 14 |
/24 |
255.255.255.0 |
256 | 254 (Standard Home/Office LAN) |
/16 |
255.255.0.0 |
65,536 | 65,534 (Typical Cloud VPC) |
3. Calculating Network and Broadcast Addresses
To find the network boundaries, the computer performs a bitwise AND between the IP address and the subnet mask:
4. RFC 1918 Private IP Ranges
Certain IP address blocks are designated as non-routable on the public Internet, reserved for internal private networks:
10.0.0.0/8(10.0.0.0 – 10.255.255.255): Large enterprises and cloud VPCs (16.7M addresses).172.16.0.0/12(172.16.0.0 – 172.31.255.255): Medium networks, Docker containers (1.04M addresses).192.168.0.0/16(192.168.0.0 – 192.168.255.255): Home routers and small office LANs (65K addresses).
Step-by-Step Bitwise AND Subnet Calculation Walkthrough
To truly understand how network routing equipment evaluates packet destinations, consider an incoming packet addressed to 192.168.10.45 with a subnet mask of 255.255.255.192 (a /26 CIDR prefix).
The network hardware converts both values into 32-bit binary registers:
The remaining 6 bits represent host addresses (2^6 = 64 total addresses). The broadcast address is calculated by setting all 6 host bits to 1, producing 192.168.10.63. The usable host range spans strictly from 192.168.10.1 to 192.168.10.62.
Multi-Tier Cloud VPC Subnet Architecture Design
In production cloud engineering (AWS, GCP, Azure), best practices dictate architecting a 3-tier VPC network topology across multiple Availability Zones (AZs) for high availability and zero-trust security isolation:
- Public Subnets (Web / Ingress Tier): Hosts internet-facing Application Load Balancers (ALBs) and NAT Gateways. Routes internet traffic directly via an Internet Gateway (IGW).
- Private Application Subnets (Compute Tier): Hosts application containers (ECS, EKS, Kubernetes worker nodes) and backend microservices. These instances have no public IP addresses; outbound traffic is routed through the NAT Gateway.
- Isolated Database Subnets (Data Tier): Hosts RDS databases, Redis caches, and persistence clusters. These subnets have no route to the internet whatsoever, preventing external data exfiltration.
5. Try Our Free Online Subnet Calculator
Calculate netmasks, binary bit visualizers, usable ranges, and CIDR prefixes locally: