AWS & Modern Cloud Architecture · Chapter 3 · ~20 min · Intermediate
VPC Networking, Subnets & CIDR Blocks
Architect production-grade virtual networks in AWS. Understand IPv4 CIDR address carving, multi-AZ high availability, the difference between public and private subnets, and packet routing via Internet Gateways and NAT Gateways.
- Design a /16 Virtual Private Cloud (VPC) with non-overlapping /24 subnets
- Differentiate Public Subnets (Internet Gateway) from Private Subnets (NAT Gateway)
- Configure custom Route Tables and the default 0.0.0.0/0 next-hop targets
- Prevent IP exhaustion by planning multi-AZ CIDR allocations and reserved AWS IPs
VPC Networking, Subnets & CIDR Blocks: learn it visually
Build private cloud networks from scratch: IPv4 CIDR block carving, 5 AWS-reserved IPs, public vs private subnets, Internet Gateways, and route table packet forwarding.
1The Virtual Private Cloud (VPC) Foundation
Before you launch an EC2 instance, an RDS relational database, or an Elastic Load Balancer, you need an isolated private network. In AWS, this dedicated network is your Virtual Private Cloud (VPC).
A VPC logically isolates your infrastructure from all other customers in AWS. You control your own private IPv4 and IPv6 address space, subnets, routing tables, and network security gateways.
CIDR Block
Classless Inter-Domain Routing notation (e.g. 10.0.0.0/16). Defines the continuous range of IP addresses available in your VPC.
Subnet
A subdivision of your VPC's IP range tied strictly to a single Availability Zone (AZ). Subnets cannot span multiple AZs.
Route Table
A set of packet forwarding rules that determine where network traffic from your subnet is directed (e.g. to the internet or locally).
Wrong idea: Deploying databases and backends directly in public subnets
Placing sensitive database servers and internal APIs in a public subnet with auto-assigned public IP addresses to make setup quick and easy.
Real system: Dual-tier architecture: public web proxies & private data layer
Isolating database and app servers inside private subnets without public IPs. Only public load balancers face the internet; backend traffic travels privately.
You create a /24 subnet (256 theoretical IP addresses) in AWS. How many usable host IP addresses are actually available for your EC2 instances?
2CIDR Math: Carving a /16 VPC into /24 Subnets
CIDR notation defines an IP prefix and subnet mask length. An IPv4 address has 32 bits. The number after the slash (/16 or /24) represents how many bits are fixed for the network prefix, leaving the remaining bits for host addresses:
/16prefix →32 - 16 = 16host bits →2^16 = 65,536total addresses./24prefix →32 - 24 = 8host bits →2^8 = 256total addresses (251 usable)./28prefix →32 - 28 = 4host bits →2^4 = 16total addresses (11 usable, AWS minimum subnet size).
{
"VpcCIDR": "10.0.0.0/16",
"SubnetAllocations": [
{ "Name": "Public-AZ-1a", "CIDR": "10.0.1.0/24", "AZ": "us-east-1a", "Role": "ALB / Bastion" },
{ "Name": "Private-AZ-1a", "CIDR": "10.0.2.0/24", "AZ": "us-east-1a", "Role": "App / Backend" },
{ "Name": "Public-AZ-1b", "CIDR": "10.0.3.0/24", "AZ": "us-east-1b", "Role": "ALB / Bastion" },
{ "Name": "Private-AZ-1b", "CIDR": "10.0.4.0/24", "AZ": "us-east-1b", "Role": "App / Backend" }
]
}3Public vs. Private Subnets: IGW vs. NAT Gateway
What makes a subnet "public" versus "private" in AWS? The answer is simple: its associated Route Table:
- Public Subnet: Its route table contains a default route (
0.0.0.0/0) pointing directly to an Internet Gateway (IGW). Instances require a Public IPv4 address to exchange bidirectional traffic with the outside web. - Private Subnet: Its route table does NOT route to an IGW. To download external patches or call third-party APIs, it points
0.0.0.0/0to a NAT Gateway located in a public subnet.
Predict first
A backend database instance is inside a private subnet. Can an attacker on the public internet initiate a connection directly to the database through the NAT Gateway?
What must be present in a subnet's route table for that subnet to be classified as a Public Subnet?
4Hands-On: Plan VPC Subnets & Trace Route Table Hops
Explore a production multi-AZ VPC layout below. Select different subnets to inspect their 5 AWS-reserved IP addresses, then simulate routing packets from web servers or backend databases out to the internet or across subnets:
Interactive VPC & Subnet CIDR Planner
Usable Host IP Range: 10.0.1.4 through 10.0.1.254 (251 usable IPs for EC2, ALBs, RDS).
5Route Tables & The Longest Prefix Match Rule
When multiple routes in a route table match a packet's destination IP address, AWS uses the Longest Prefix Match rule. The route with the most specific (highest prefix length) CIDR mask always wins:
A packet is sent to IP 10.0.1.50. The route table has entries for '10.0.0.0/16 -> local' and '0.0.0.0/0 -> igw-xxx'. Which route is used?
6Bug Hunt: Fix the Public Subnet Route Table
A DevOps engineer created this route table for a public web tier, but web servers cannot connect to the internet. Find and fix the CIDR and gateway target errors below, then click Run & verify:
🎯 Find and fix the bugs in the code above, then press Run & verify to test your solution.
Need a hint?
- Keep the VPC internal route
10.0.0.0/16targetinglocal. - The universal default route for all internet traffic is
0.0.0.0/0, not0.0.0.0/32. - Public subnets route internet traffic to an Internet Gateway (
igw-...), not a NAT Gateway.
7Chapter Knowledge Challenge
Validate your knowledge of VPCs, subnets, CIDR notation, and route tables:
Why must a NAT Gateway itself be placed in a Public Subnet with an Elastic IP address?
Can a single Amazon VPC subnet span across multiple Availability Zones (e.g. us-east-1a and us-east-1b)?
8Recap
- An Amazon VPC is your private, isolated virtual network slice within an AWS Region.
- CIDR Math: A
/16VPC has 65,536 addresses, typically carved into non-overlapping/24subnets (251 usable host IPs each). - 5 Reserved IPs: AWS reserves the first 4 addresses (.0, .1, .2, .3) and the last address (.255) in every subnet.
- Public vs Private: Public subnets route
0.0.0.0/0to an Internet Gateway; private subnets route to a NAT Gateway for egress-only updates. - Longest Prefix Match: Route tables forward packets using the most specific matching CIDR rule.
Ready for Chapter 4 (Security Groups vs NACLs)? Mark this chapter as complete to proceed: