AWS VPC Explained: Subnets, Route Tables, and the Internet Gateway
A working mental model for AWS VPCs: what each piece does, how they connect, and why "VPC" is the wrong mental model if you came from physical networks.
Key takeaways
- An AWS VPC is a private network defined entirely by configuration.
- Subnets are slices of its address range, each in one Availability Zone.
- A subnet is public only because its route table sends 0.0.0.0/0 to an internet gateway; private subnets reach out through a NAT gateway or not at all.
On this page
An AWS VPC is your own isolated network in AWS, defined entirely by configuration: an address range (CIDR), subnets that each live in one Availability Zone, route tables, and gateways. A subnet is "public" only because its route table sends 0.0.0.0/0 to an internet gateway. Below, we build one end to end with the AWS CLI.
Verified against
AWS CLI 2.39.3, against the Amazon VPC User Guide (CIDR sizing, internet gateways, NAT gateways) and the AWS VPC pricing page. Checked October 2026.
About 25 minutes. You'll need an AWS account and the AWS CLI v2 installed and configured. The VPC, subnets, route table and internet gateway are free; the test instance and its public IPv4 address are not (AWS charges $0.005 per hour per public IPv4 address, as of October 2026), so clean up when you're done.
The mental shift
If you came from physical networks, the temptation is to map AWS networking onto VLANs, switches, and routers. Resist it. AWS networking is not switches and routers. It's configuration that defines connectivity. There are no wires. Two EC2 instances can be in adjacent IP ranges and totally unable to reach each other if the route tables and security groups don't allow it.
That's the core insight. Once it lands, everything else slots in.
The five pieces
A VPC has five parts you need to understand:
- VPC: a private network in AWS. Has a CIDR block (e.g.
10.0.0.0/16). - Subnet: a slice of the VPC's CIDR, bound to a single Availability Zone (AZ).
- Route table: rules saying "for this destination CIDR, send traffic to this target."
- Internet gateway (IGW): the thing that lets traffic in/out of the public internet. It's free; you pay for the data transfer.
- NAT gateway: lets private instances reach the internet out without being reachable in. Billed per hour plus per GB processed.
That's the whole vocabulary you need to read most VPC diagrams.
Step 1: Create a VPC
$ aws ec2 create-vpc --cidr-block 10.0.0.0/16 --tag-specifications \
'ResourceType=vpc,Tags=[{Key=Name,Value=tutorial-vpc}]'
You'll get back a VPC object. Note the VpcId (e.g. vpc-0abc123...). Save it:
$ export VPC=vpc-0abc123... # paste your VPC ID
That's a /16: 65,536 addresses, and the largest IPv4 block AWS allows for a VPC (the range is /16 to /28). Way more than you need for a tutorial, but it's the common default because you can't easily grow a VPC later. You split it into smaller subnets.
Step 2: Create two subnets
A "public" subnet (where instances can reach the internet) and a "private" subnet (where they can't):
$ aws ec2 create-subnet --vpc-id $VPC --cidr-block 10.0.1.0/24 \
--availability-zone us-east-1a --tag-specifications \
'ResourceType=subnet,Tags=[{Key=Name,Value=tutorial-public}]'
$ aws ec2 create-subnet --vpc-id $VPC --cidr-block 10.0.2.0/24 \
--availability-zone us-east-1a --tag-specifications \
'ResourceType=subnet,Tags=[{Key=Name,Value=tutorial-private}]'
Save both subnet IDs:
$ export PUBLIC_SUBNET=subnet-0...
$ export PRIVATE_SUBNET=subnet-0...
Each /24 gives you 251 usable addresses, not 256: AWS reserves the first four and the last address in every subnet (network address, VPC router, DNS, future use, broadcast).
Important
There is no flag on a subnet that makes it "public" or "private." That distinction comes from the route table, which we'll get to. The names are descriptive, not functional.
Step 3: Create an internet gateway and attach it
$ aws ec2 create-internet-gateway --tag-specifications \
'ResourceType=internet-gateway,Tags=[{Key=Name,Value=tutorial-igw}]'
Save the InternetGatewayId:
$ export IGW=igw-0...
Attach it to the VPC:
$ aws ec2 attach-internet-gateway --internet-gateway-id $IGW --vpc-id $VPC
The IGW is now part of the VPC, but no traffic flows yet. We need a route table that points at it.
Step 4: Create the public route table
$ aws ec2 create-route-table --vpc-id $VPC --tag-specifications \
'ResourceType=route-table,Tags=[{Key=Name,Value=tutorial-public-rt}]'
Save it:
$ export PUBLIC_RT=rtb-0...
Add a route: "for any destination (0.0.0.0/0), send traffic to the IGW."
$ aws ec2 create-route --route-table-id $PUBLIC_RT --destination-cidr-block 0.0.0.0/0 \
--gateway-id $IGW
That's the line that makes a route table "public": a default route to an IGW. Same VPC's other route table, no such route, becomes "private."
Now associate the public subnet with the public route table:
$ aws ec2 associate-route-table --route-table-id $PUBLIC_RT --subnet-id $PUBLIC_SUBNET
$ aws ec2 modify-subnet-attribute --subnet-id $PUBLIC_SUBNET --map-public-ip-on-launch
The second command matters more than it looks. In a VPC you create yourself, instances don't get a public IPv4 address by default, and the AWS docs are explicit that an instance needs one (or an Elastic IP) to use the internet gateway. Without it, the route exists and traffic still goes nowhere.
Step 5: Verify connectivity
The simplest test: launch a small EC2 instance into the public subnet and try to reach the internet.
# A new security group allows all outbound traffic by default
$ aws ec2 create-security-group --vpc-id $VPC --group-name tutorial-sg \
--description "tutorial"
$ export SG=sg-0...
# Allow SSH from your IP only
$ MYIP=$(curl -s https://checkip.amazonaws.com)
$ aws ec2 authorize-security-group-ingress --group-id $SG \
--protocol tcp --port 22 --cidr ${MYIP}/32
Launch an Amazon Linux EC2 in the public subnet. (Use the AWS console for this if you don't have key pairs configured for the CLI; quicker.) When it's running, SSH into it and:
$ curl -sI https://example.com
You should get HTTP headers back. The packets traveled: instance, public subnet, public route table, internet gateway, internet.
If you launched the same instance into the private subnet instead, with no route table changes, the same curl would hang. Same instance, same security group, but the route table doesn't know how to reach 0.0.0.0/0, so the packet is dropped at the boundary.
That's the whole "configuration defines connectivity" lesson in one experiment.
Step 6: Cleanup
When done, delete in reverse order so AWS doesn't complain about dependencies:
$ aws ec2 terminate-instances --instance-ids <your-instance>
$ aws ec2 wait instance-terminated --instance-ids <your-instance>
$ aws ec2 delete-security-group --group-id $SG
$ aws ec2 disassociate-route-table --association-id <rtbassoc-id>
$ aws ec2 delete-route-table --route-table-id $PUBLIC_RT
$ aws ec2 detach-internet-gateway --internet-gateway-id $IGW --vpc-id $VPC
$ aws ec2 delete-internet-gateway --internet-gateway-id $IGW
$ aws ec2 delete-subnet --subnet-id $PUBLIC_SUBNET
$ aws ec2 delete-subnet --subnet-id $PRIVATE_SUBNET
$ aws ec2 delete-vpc --vpc-id $VPC
The association ID came back from associate-route-table; aws ec2 describe-route-tables --route-table-ids $PUBLIC_RT shows it again if you lost it.
Common mistakes
Forgetting that subnets are zonal, not regional. A subnet lives in exactly one AZ. For HA, you need multiple subnets, typically one per AZ.
Confusing security groups with route tables. Route tables decide where traffic goes. Security groups decide whether it's allowed when it arrives. Both have to permit a packet for it to flow. Most "I can't connect" debugging fails to check both.
CIDR blocks too small. A /27 (32 addresses, 27 usable after AWS's five reserved) seems fine until your EKS cluster eats them all in pod IPs. For new VPCs, /16 is a safe default. For subnets, /22 for container workloads, /24 for VM-only.
Building a private subnet without a NAT gateway and being surprised when apt-get update hangs. Private subnets can't reach the internet by default. If they need to (for package updates, S3 access, etc.) you either need a NAT gateway (for general internet) or VPC endpoints (for AWS services specifically).
To plan the address ranges, the CIDR and subnet calculator has an AWS mode that subtracts the five reserved addresses and splits a VPC block into per-AZ subnets.
Questions people ask
What makes a subnet public or private in AWS?
Only its route table. A subnet associated with a route table that has a route to an internet gateway (usually 0.0.0.0/0) is public; one without that route is private. There's no public/private flag on the subnet itself. Instances in a public subnet still need a public IPv4 address or Elastic IP to actually reach the internet.
Do I need a NAT gateway for a private subnet?
Only if instances in it must start connections to the internet, for example to download packages. A NAT gateway allows outbound traffic while blocking inbound connections, and it bills per hour plus per GB processed. If the traffic only goes to AWS services like S3 or DynamoDB, VPC endpoints are often cheaper than a NAT gateway.
How big should my VPC CIDR block be?
AWS allows IPv4 VPC blocks from /16 (65,536 addresses) down to /28 (16 addresses). Use a /16 for anything that might grow, especially if Kubernetes pods take VPC IPs. Pick a range that won't overlap with your office network or other VPCs, because overlapping ranges block peering and VPN connections later.
What to read next
You've got the core pieces. The next levels:
- Networking fundamentals guide: CIDR, routing and DNS from first principles, the layer under every VPC
- NAT gateway costs: cutting the silent line item: what the private-subnet egress path really costs and how to shrink it
- AWS S3 tutorial: buckets and permissions: the next AWS building block, and a common reason to add a VPC endpoint
VPCs are not switches and routers. They're configuration. Once that lands, the AWS networking docs stop being terrifying and start being useful.
Sources
Cite this article
Kiril Urbonas (2026). AWS VPC Explained: Subnets, Route Tables, and the Internet Gateway. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/aws-vpc-explained-beginner-guide
[AWS VPC Explained: Subnets, Route Tables, and the Internet Gateway](https://www.devopsness.com/blog/aws-vpc-explained-beginner-guide) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from Cloud
Explore more articles in this category
.NET 8 Support Ends November 10: The Lambda and Azure Functions Checklist
.NET 8, .NET 9, the Lambda dotnet8 runtime and the Azure Functions in-process model all lose support on November 10, 2026. Inventory commands, the isolated-worker migration and a CI gate.
Google Cloud's europe-west2 Outage: One Zone Lost Power and the Region Stalled for 6 Hours
On October 20, 2026, europe-west2-b lost power when its generators never started. Cross-zone control-plane timeouts then degraded the whole London region. What happened and the gcloud audit to run now.
Lambda Python 3.10 Is Deprecated Today: Find Every Function and Move to 3.13
AWS deprecated the Lambda python3.10 runtime on October 31, 2026. Functions keep running, patches stop. The inventory commands, IaC diffs and AL2023 gotchas for moving to python3.13.
You might have missed
Evergreen posts worth revisiting.