0Pricing
AWS Solutions Architect · Lesson

VPC Architecture and CIDR Blocks

Design a VPC with an appropriate CIDR range, divide it into public and private subnets across Availability Zones.

VPC Architecture and CIDR Blocks is a free AWS Solutions Architect lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Solutions Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Is a VPC?

An Amazon Virtual Private Cloud (VPC) is a logically isolated private network within an AWS Region that you define and control. Every AWS account comes with a default VPC (CIDR 172.31.0.0/16) in each Region, but production architectures always use custom VPCs. A VPC spans all Availability Zones in its Region and gives you full control over IP addressing, subnets, route tables, internet gateways, and security. Resources inside a VPC are isolated from other VPCs and from the internet unless you explicitly configure connectivity.

# Create a custom VPC
aws ec2 create-vpc \
  --cidr-block 10.0.0.0/16 \
  --tag-specifications 'ResourceType=vpc,Tags=[{Key=Name,Value=production-vpc}]'

CIDR Blocks: IP Address Ranges

A CIDR (Classless Inter-Domain Routing) block defines the IP address range of a VPC or subnet using the format x.x.x.x/prefix. The prefix length determines how many IP addresses are in the range: /16 = 65,536 addresses, /24 = 256 addresses, /28 = 16 addresses (minimum subnet size on AWS). For VPCs, AWS allows CIDR blocks from /16 (largest) to /28 (smallest). Choose a VPC CIDR that: (1) does not overlap with on-premises networks (for future VPN/Direct Connect), (2) is large enough for your planned subnets, and (3) uses private RFC 1918 address space (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16).

# Common VPC CIDR choices:
# 10.0.0.0/16   -> 65,534 usable IPs (largest common choice)
# 10.0.0.0/20   -> 4,094 usable IPs
# 10.0.0.0/24   -> 254 usable IPs (too small for most VPCs)

# AWS reserves 5 IPs in each subnet:
# x.x.x.0   Network address
# x.x.x.1   VPC router
# x.x.x.2   DNS server
# x.x.x.3   Future use
# x.x.x.255  Broadcast

Subnets: Dividing the VPC

A subnet is a segment of a VPC's IP address range that lives in a single Availability Zone. Subnets are classified as public (has a route to an internet gateway) or private (no direct internet route). Best practice for a typical 3-tier architecture: create at least three subnet tiers—public (load balancers, bastion hosts), private-app (EC2 instances, ECS tasks), and private-data (RDS, ElastiCache)—and replicate each tier across at least two AZs for high availability.

# Create a public subnet in AZ-a
aws ec2 create-subnet \
  --vpc-id vpc-12345678 \
  --cidr-block 10.0.1.0/24 \
  --availability-zone us-east-1a \
  --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=public-1a}]'

# Create a private subnet in AZ-a
aws ec2 create-subnet \
  --vpc-id vpc-12345678 \
  --cidr-block 10.0.10.0/24 \
  --availability-zone us-east-1a \
  --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=private-app-1a}]'

Designing a Multi-AZ VPC CIDR Layout

A common CIDR design for a VPC with CIDR 10.0.0.0/16 across two AZs and three tiers: Public AZ-a: 10.0.1.0/24; Public AZ-b: 10.0.2.0/24; Private-App AZ-a: 10.0.10.0/24; Private-App AZ-b: 10.0.11.0/24; Private-Data AZ-a: 10.0.20.0/24; Private-Data AZ-b: 10.0.21.0/24. This layout leaves room to add AZ-c subnets (10.0.3.0/24, 10.0.12.0/24, 10.0.22.0/24) without re-planning the entire CIDR scheme. Always design with growth in mind.

Reserved IPs in Each Subnet

AWS reserves the first four and last IP address in every subnet. For a 10.0.1.0/24 subnet: 10.0.1.0 (network), 10.0.1.1 (VPC router), 10.0.1.2 (DNS/DHCP), 10.0.1.3 (future use), and 10.0.1.255 (broadcast). A /24 subnet has 256 total IPs minus 5 reserved = 251 usable. A /28 subnet (the minimum) has 16 IPs minus 5 = 11 usable. This matters when sizing subnets for the number of resources (EC2 instances, Lambda functions with VPC, etc.) you plan to deploy.

VPC Secondary CIDR Blocks

You can add up to four secondary CIDR blocks to an existing VPC without re-creating it. This is useful when your primary CIDR is exhausted (all subnets full) or when you need to add address space from a different RFC 1918 range for a specific use case like Kubernetes pod networking. The secondary CIDRs are subject to certain restrictions—for example, you cannot add an overlapping CIDR, and certain non-RFC-1918 public ranges cannot be used. Plan VPC CIDR sizing carefully upfront to minimise the need for secondary CIDRs.

# Add a secondary CIDR to an existing VPC
aws ec2 associate-vpc-cidr-block \
  --vpc-id vpc-12345678 \
  --cidr-block 10.1.0.0/16

VPC Peering: Connecting VPCs

VPC Peering establishes a private network connection between two VPCs so their resources can communicate using private IP addresses. Peered VPCs can be in the same account, different accounts, or even different Regions (inter-region peering). Requirements: the CIDRs of the two VPCs must not overlap. Limitations: peering is non-transitive—if VPC-A peers with VPC-B and VPC-B peers with VPC-C, VPC-A cannot communicate with VPC-C through VPC-B. For full mesh connectivity across many VPCs, use AWS Transit Gateway instead.

AWS Transit Gateway

AWS Transit Gateway (TGW) acts as a central network hub—a cloud router—that connects multiple VPCs, VPNs, and Direct Connect connections. Instead of creating N*(N-1)/2 VPC peering connections for a full mesh of N VPCs, you attach each VPC and connection to the Transit Gateway, which routes traffic between them. TGW supports route tables that let you control which attachments can communicate with each other, enabling network segmentation (e.g., isolate production VPCs from dev VPCs on the same TGW).

Enabling DNS in a VPC

Two DNS settings control name resolution in a VPC. enableDnsSupport: when true (default), the VPC uses the AWS-provided DNS resolver at 169.254.169.253 or the second IP of the VPC CIDR (e.g., 10.0.0.2 for 10.0.0.0/16). enableDnsHostnames: when true (must be enabled for custom VPCs, default on for the default VPC), EC2 instances in the VPC receive DNS hostnames like ip-10-0-1-15.ec2.internal. Both must be enabled for Route 53 Private Hosted Zones to work within the VPC.

# Enable DNS support and DNS hostnames in a VPC
aws ec2 modify-vpc-attribute \
  --vpc-id vpc-12345678 \
  --enable-dns-support '{"Value": true}'
aws ec2 modify-vpc-attribute \
  --vpc-id vpc-12345678 \
  --enable-dns-hostnames '{"Value": true}'

VPC Flow Logs

VPC Flow Logs capture metadata about network traffic flowing through your VPC—source and destination IP, port, protocol, bytes transferred, and whether the traffic was accepted or rejected. Flow logs can be published to CloudWatch Logs (for querying with Logs Insights) or S3 (for analysis with Athena). They are invaluable for security forensics (who connected to what), traffic analysis (identify high-bandwidth flows), and troubleshooting (why was a connection rejected?). Flow logs operate at the VPC, subnet, or individual ENI level.

# Enable flow logs for a VPC, deliver to CloudWatch
aws ec2 create-flow-logs \
  --resource-type VPC \
  --resource-ids vpc-12345678 \
  --traffic-type ALL \
  --log-destination-type cloud-watch-logs \
  --log-group-name /aws/vpc/flowlogs \
  --deliver-logs-permission-arn arn:aws:iam::123456789012:role/FlowLogsRole

Planning for Connectivity

Before creating a VPC, plan for all future connectivity needs: On-premises connectivity (VPN or Direct Connect)—ensure VPC CIDR does not overlap with on-premises subnets; Cross-VPC connectivity (peering or Transit Gateway)—plan non-overlapping CIDRs across all VPCs in your organisation; AWS service access (VPC endpoints for S3, DynamoDB, SSM to avoid traffic going through the internet); and subnet sizing—leave headroom in each subnet for IP address consumption from EKS pods, Lambda functions, and Elastic Network Interfaces.

Quick Check

Test your understanding of AWS Solutions Architect (SAA-C03) concepts from this lesson.

Lesson Recap

In this lesson you learned: a VPC is a logically isolated network in a Region, defined by a CIDR block that you divide into public and private subnets across AZs, AWS reserves 5 IPs in every subnet so always size subnets with this reduction in mind, and VPC Peering and Transit Gateway connect VPCs privately, but CIDR ranges must not overlap. Next up we explore Internet Gateways and Route Tables.

Frequently asked questions

Is the “VPC Architecture and CIDR Blocks” lesson free?

Yes — the full text of “VPC Architecture and CIDR Blocks” is free to read here on the web, and the AWS Solutions Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Solutions Architect course, upgrade to CoddyKit PRO.

What will I learn in “VPC Architecture and CIDR Blocks”?

Design a VPC with an appropriate CIDR range, divide it into public and private subnets across Availability Zones. You practise AWS Solutions Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start AWS Solutions Architect?

No prior experience is required. AWS Solutions Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “VPC Architecture and CIDR Blocks” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this AWS Solutions Architect lesson?

Yes. Every AWS Solutions Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. VPC Architecture and CIDR Blocks
  2. Internet Gateway and Route Tables
  3. NAT Gateway and Private Subnets
  4. Network ACLs vs Security Groups
← Back to AWS Solutions Architect