IP Subnetting and CIDR Notation: Network Architecture and Routing Guide
Master IPv4 subnetting, Classless Inter-Domain Routing (CIDR), subnet masks, network vs broadcast addresses, and VPC IP allocation for cloud engineers.
1. IPv4 Binary Fundamentals: Octets, Subnet Masks, and Prefix Lengths
An IPv4 address consists of 32 binary bits divided into four 8-bit octets separated by dots (e.g. `192.168.1.1`). A subnet mask separates the 32 bits into a network portion (identifying the subnet) and a host portion (identifying specific devices on that subnet). Calculate ranges and masks instantly with the Subnet Calculator.
Bitwise calculation of network and broadcast boundaries
IP Address: 192.168.1.50 -> 11000000.10101000.00000001.00110010
Subnet Mask: 255.255.255.0 -> 11000000.11111111.11111111.00000000
Bitwise AND: 192.168.1.0 (Network Address)
Broadcast: 192.168.1.255 (Broadcast Address)
Usable Hosts: 192.168.1.1 through 192.168.1.254 (254 Total Hosts)
2. Classless Inter-Domain Routing (CIDR) vs. Legacy Classful Networks
Historical IPv4 networking divided addresses into rigid classes: Class A (/8, 16.7M hosts), Class B (/16, 65,536 hosts), and Class C (/24, 254 hosts). This led to massive IP address wastage. CIDR (RFC 1519) replaced classful addressing with variable-length prefix notation (e.g., `/27`), allowing network architects to allocate subnets tailored precisely to required host capacities.
3. Calculating Usable Host Ranges and Broadcast Boundaries
For any subnet with prefix length $n$, the total number of IP addresses is $2^{(32-n)}$. In standard networking, two addresses are reserved:
• Network Address (all host bits 0): Identifies the subnet itself.
• Broadcast Address (all host bits 1): Used to broadcast traffic to all nodes on the subnet.
Therefore, usable host capacity equals $2^{(32-n)} - 2$. (Note: Major cloud providers like AWS reserve 5 addresses per subnet: network, router, DNS, future use, and broadcast).
4. Subnet Allocation Best Practices for Cloud VPCs (AWS/GCP/Azure)
When designing a Virtual Private Cloud (VPC), structure subnets into distinct availability zones and routing tiers:
• Public Subnets (/24 to /26): Host ingress load balancers and NAT gateways.
• Private Application Subnets (/22 to /24): Host container clusters, microservices, and compute nodes.
• Isolated Database Subnets (/26 to /28): Host relational database replicas with no outbound internet routes.
5. Common Subnetting Errors and Supernetting (CIDR Aggregation)
Ensure adjacent subnets do not overlap in address space, which causes routing table conflicts and dropped packets. Supernetting aggregates multiple contiguous smaller subnets into a single larger route advertisement, reducing the size and memory consumption of core internet routing tables.
Key Takeaways
CIDR notation (/n) indicates the number of consecutive leading 1-bits in the subnet mask.
Usable hosts in a standard IPv4 subnet equal 2^(32-n) - 2.
Cloud providers (e.g. AWS VPC) reserve 5 addresses per subnet, not just 2.
Plan cloud VPC subnets with room for growth to prevent complex re-IP migrations.