VPC, Subnets, Route Tables and Internet Gateways
Build a VPC from scratch with public and private subnets across two AZs and understand exactly what makes a subnet public.
Intermediate · about 6 hours · difficulty 3/5
Learn first: Networking Fundamentals: IP, CIDR, TCP and Ports, IAM Users, Groups, Roles and Policies, Global Infrastructure: Regions, AZs and Edge
A Virtual Private Cloud (VPC) is your own isolated network inside an AWS region. Azure calls it a Virtual Network (VNet); Google Cloud calls it a VPC but makes it global.
The building blocks
- CIDR block: the address range of the VPC, for example 10.0.0.0/16.
- Subnets: slices of that range, each living in exactly one AZ. A typical layout has public, private (app) and database subnets in two or three AZs.
- Route tables: rules attached to subnets that decide where traffic goes. Every route table has a local route for the VPC CIDR.
- Internet Gateway (IGW): attached to the VPC, it lets resources with public IPs reach the internet and be reached from it.
What makes a subnet public
A subnet is public only because its route table has a route 0.0.0.0/0 to the Internet Gateway. There is no "public" checkbox. Instances also need a public IPv4 or Elastic IP to be reachable.
The default VPC
Every region comes with a default VPC where all subnets are public. It is handy for quick tests but not how production is built. Learn to create your own.
Design tips
- Pick a /16 that does not overlap with other VPCs, offices or partner networks.
- Leave spare address space for future subnets.
- Put only load balancers and bastion-type resources in public subnets; keep app servers and databases private.
Pitfalls
- Placing databases in public subnets "to make connecting easier".
- Creating subnets in only one AZ, which defeats high availability.
You are ready to move on when you can build a two-AZ VPC with public and private subnets by hand in the console, then explain each route table entry.
Key concepts
- VPC CIDR planning
- Subnets and AZs
- Route tables
- Internet Gateway
- Public vs private subnets
- Default VPC
- Elastic IPs: Billed hourly as public IPv4
- IPv6 in VPCs
Mini project
Create a VPC in ap-south-1 with two public and two private subnets across two AZs, an Internet Gateway and correct route tables. Draw the diagram in draw.io and commit it to your repo. VPCs, subnets and route tables are free; do not add a NAT Gateway yet, and delete the VPC when done.
Check yourself
Two subnets in the same VPC have identical NACLs and security groups. One is public, one is private. What is the only difference?
Free resources
- Amazon VPC User Guide (AWS)
- Amazon VPC documentation (AWS)
- The Open Guide to AWS: VPCs (open-guides)