Chapter 3 of 12
Course Progress0 of 12 completed (0%)

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.

VPC Networking, Subnets & CIDR BlocksBuild private cloud networks from scratch: IPv4 CIDR block carving, 5 AWS-reserved IPs, public vs private subnets, Internet Gateways, and route table packet forwarding.UNDERSTANDVPC NetworkingFOLLOW THE FLOWSubnetsAPPLY ITCIDR BlocksVPC Networking, Subnets & CIDR BlocksBuild private cloud networks from scratch: IPv4 CIDR block carving, 5 AWS-reserved IPs, public vs private subnets, Internet Gateways, and route table packet forwarding.UNDERSTANDVPC NetworkingFOLLOW THE FLOWSubnetsAPPLY ITCIDR Blocks

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

Internet → Public IP (54.210.12.4) → MySQL Port 3306Exposed to brute force scans · zero network perimeter defense

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

Internet → Public ALB → Private Subnet (10.0.2.50) → MySQLNo direct internet ingress · outbound updates route via NAT Gateway

Isolating database and app servers inside private subnets without public IPs. Only public load balancers face the internet; backend traffic travels privately.

Concept Check

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:

  • /16 prefix → 32 - 16 = 16 host bits → 2^16 = 65,536 total addresses.
  • /24 prefix → 32 - 24 = 8 host bits → 2^8 = 256 total addresses (251 usable).
  • /28 prefix → 32 - 28 = 4 host bits → 2^4 = 16 total 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/0 to 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?

Concept Check

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

VPC: 10.0.0.0/16 (65,536 IPs)
VPC Subnet Architecture (Carved across 2 Availability Zones):
Availability Zone: us-east-1a
AZ ID: use1-az1
Public Subnet 1 (Web)
PUBLIC
CIDR: 10.0.1.0/24251 usable hosts
Private Subnet 1 (App/DB)
PRIVATE
CIDR: 10.0.2.0/24251 usable hosts
Availability Zone: us-east-1b
AZ ID: use1-az2
Public Subnet 2 (Web)
PUBLIC
CIDR: 10.0.3.0/24251 usable hosts
Private Subnet 2 (App/DB)
PRIVATE
CIDR: 10.0.4.0/24251 usable hosts
Selected Subnet Inspector: Public Subnet 1 (Web)10.0.1.0/24
1. Network Address:10.0.1.0Reserved by AWS
2. VPC Router:10.0.1.1Reserved by AWS
3. Amazon DNS (Route 53):10.0.1.2Base + 2 Reserved
4. Future Reserved:10.0.1.3Reserved by AWS
5. Broadcast Address:10.0.1.255Reserved by AWS

Usable Host IP Range: 10.0.1.4 through 10.0.1.254 (251 usable IPs for EC2, ALBs, RDS).

Packet Route Table Simulator

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:

Destination CIDRTargetMatch Priority
10.0.2.14/32 (Single Host)eni-0123 (Specific Interface)Highest Priority (/32)
10.0.0.0/16 (VPC CIDR)local (VPC Router)Medium Priority (/16)
0.0.0.0/0 (Default Internet)igw-0abc (Internet Gateway)Lowest Priority / Fallback (/0)
Concept Check

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:

VPC Route Table JSON Bug Hunt · Public Internet Route
JSON

🎯 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/16 targeting local.
  • The universal default route for all internet traffic is 0.0.0.0/0, not 0.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:

Concept Check

Why must a NAT Gateway itself be placed in a Public Subnet with an Elastic IP address?

Concept Check

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 /16 VPC has 65,536 addresses, typically carved into non-overlapping /24 subnets (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/0 to 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:

Enjoying this free lesson? Your support helps us build more free animated chapters.

Support Us