Every EC2 instance, RDS database, and Lambda function you run in AWS lives inside a network that you define. That network is Amazon Virtual Private Cloud, and understanding amazon vpc basics is what separates a cloud setup that is secure by design from one that is exposed by accident. In this guide you will learn how a VPC is structured, how subnets, route tables, internet gateways, NAT gateways, security groups, and network ACLs fit together, and you will build a practical two-tier VPC step by step with the AWS CLI.
If you have not launched a server yet, start with our guide on how to launch your first EC2 instance on AWS, then return here to place your next instances in a network you control. More tutorials like this one are collected in our AWS category.
What Is a VPC and Why Does It Matter?
A VPC is a logically isolated section of the AWS cloud where you define the IP address range, subnets, routing, and access rules. AWS creates a default VPC in every region, which is convenient for experiments but rarely right for production: its subnets are all public. Learning amazon vpc basics means being able to design your own VPC where application servers can reach the internet, databases cannot be reached from the internet at all, and every traffic flow is deliberate. The official Amazon VPC documentation is the definitive reference for each component described below.
Amazon VPC Basics: Planning Your CIDR Block
Every VPC starts with a private IPv4 CIDR block, most commonly a /16 such as 10.0.0.0/16, which gives you 65,536 addresses to carve into subnets. Plan before you create anything, because the primary CIDR cannot be changed later. A simple, readable scheme is to reserve one /24 per subnet type per Availability Zone: for example 10.0.1.0/24 and 10.0.2.0/24 for public subnets in two zones, and 10.0.11.0/24 and 10.0.12.0/24 for private subnets. Keep the ranges non-overlapping with your office network or any VPC you may peer with later, and leave spare blocks for future tiers. Good CIDR planning is the foundation of amazon vpc basics, and it costs nothing to do well at the start.
Prerequisites
- An AWS account with permission to create VPC resources (see our IAM guide for a secure admin setup).
- The AWS CLI version 2 installed, configured, and verified with
aws sts get-caller-identity. - A chosen AWS region and two Availability Zones in that region, for example us-east-1a and us-east-1b.
- A written CIDR plan, even if it is just a few lines in a notebook.
Public vs Private Subnets, Gateways, and Route Tables
A subnet is a range of addresses inside one Availability Zone. What makes a subnet public or private is not a checkbox; it is its route table. A public subnet has a route to an internet gateway (IGW), an AWS-managed gateway attached to the VPC that allows traffic to and from the internet. A private subnet has no IGW route. Instead, its outbound route usually points to a NAT gateway, which sits in a public subnet, has an Elastic IP, and lets private instances download updates and call APIs without ever accepting inbound connections from the internet.
Route tables are the rulebooks: each subnet is associated with exactly one route table, and each route says “traffic for this destination CIDR goes to this target”. The local route for the VPC CIDR always exists and cannot be deleted, which is how subnets talk to each other inside the VPC.

Amazon VPC Basics in Practice: A Two-Tier Example
Now build the classic two-tier design: web servers in public subnets, application and database servers in private subnets. The same amazon vpc basics apply in the console, but the CLI makes every step repeatable.
Step 1: Create the VPC and subnets
aws ec2 create-vpc --cidr-block 10.0.0.0/16 \
--tag-specifications 'ResourceType=vpc,Tags=[{Key=Name,Value=main-vpc}]'
aws ec2 create-subnet --vpc-id vpc-0123456789abcdef0 \
--cidr-block 10.0.1.0/24 --availability-zone us-east-1a
aws ec2 create-subnet --vpc-id vpc-0123456789abcdef0 \
--cidr-block 10.0.11.0/24 --availability-zone us-east-1a
Replace the VPC ID with the value returned by the first command. Repeat the subnet commands for your second Availability Zone with the 10.0.2.0/24 and 10.0.12.0/24 blocks.
Step 2: Attach an internet gateway and configure the public route table
aws ec2 create-internet-gateway
aws ec2 attach-internet-gateway \
--internet-gateway-id igw-0123456789abcdef0 \
--vpc-id vpc-0123456789abcdef0
aws ec2 create-route-table --vpc-id vpc-0123456789abcdef0
aws ec2 create-route --route-table-id rtb-0123456789abcdef0 \
--destination-cidr-block 0.0.0.0/0 \
--gateway-id igw-0123456789abcdef0
aws ec2 associate-route-table --route-table-id rtb-0123456789abcdef0 \
--subnet-id subnet-0aaa1111bbbb2222
Associate this route table only with the public subnets. The 0.0.0.0/0 route is what officially makes them public.
Step 3: Add a NAT gateway for the private subnets
aws ec2 allocate-address --domain vpc
aws ec2 create-nat-gateway \
--subnet-id subnet-0aaa1111bbbb2222 \
--allocation-id eipalloc-0123456789abcdef0
aws ec2 create-route --route-table-id rtb-0ccc3333dddd4444 \
--destination-cidr-block 0.0.0.0/0 \
--nat-gateway-id nat-0123456789abcdef0
Create a second route table for the private subnets with the NAT route above, and associate it with them. Remember that NAT gateways are billed hourly and per gigabyte, so many teams run one per Availability Zone for production resilience and a single shared one for development.
Security Groups vs Network ACLs
Two firewall layers protect your subnets, and confusing them is a common beginner mistake. Security groups are stateful firewalls attached to instances and other resources: allow rules only, and return traffic is automatically permitted. If you allow inbound SSH on port 22, the replies flow out without an extra rule. Network ACLs (NACLs) are stateless firewalls attached to subnets: they have numbered allow and deny rules, are evaluated in order, and you must explicitly allow return traffic on ephemeral ports. As a practical rule, do your day-to-day filtering with security groups (for example, the database security group only accepts port 3306 from the application security group), and use NACLs as a coarse second layer, for instance to block a known abusive IP range at the subnet edge. Mastering this distinction is one of the most useful amazon vpc basics you can learn.
Troubleshooting Common VPC Problems
An instance in a public subnet has no internet access
Check, in order: does the instance have a public IP or Elastic IP, is the internet gateway attached to the VPC, does the subnet route table contain the 0.0.0.0/0 route to the IGW, and does the security group allow outbound traffic? One missing item breaks the chain.
A private instance cannot download updates
Verify the NAT gateway is in a public subnet (not a private one), that it has an Elastic IP, that its state is available, and that the private route table points 0.0.0.0/0 to the NAT gateway. Also check NACLs for missing ephemeral port rules.
Two subnets cannot reach each other
Intra-VPC traffic uses the local route, so the culprit is almost always a security group rule or a NACL. Test by temporarily allowing all traffic within the VPC CIDR in the NACL, then narrow the rules back down one at a time.
"The CIDR is in use" or overlapping ranges when peering
You overlapped address space with an existing subnet or a peer VPC. This cannot be fixed in place; you must create a new subnet (or VPC) with a free block from your plan, which is why the planning step matters.
Conclusion
You now have the full picture of amazon vpc basics: choose a clean CIDR plan, split subnets into public and private tiers across at least two Availability Zones, route public traffic through an internet gateway and private outbound traffic through a NAT gateway, and filter with stateful security groups backed by stateless NACLs. Build this two-tier VPC once by hand, save the CLI commands as a script or convert them to infrastructure as code, and every future project can start from a network that is secure, predictable, and easy to explain.