
VPC Explained: The Network Behind Every AWS Workload
A beginner-friendly guide to subnets, routing, and the layers that decide who can talk to what.
For many beginners, networking is the topic that makes AWS feel hard. This article builds the mental model in layers, so each piece makes sense before the next one arrives.
The Mental Model: A Gated Neighborhood
Think of a VPC as a gated neighborhood:
- The VPC is the whole neighborhood, with its own address space.
- Subnets are streets within it, each located in one specific Availability Zone.
- Route tables are the road signs that tell traffic where to go.
- An internet gateway is the main gate to the outside world.
- Security groups and network ACLs are the guards and locks at different checkpoints.
Keep this picture in mind. Every concept below is one of these pieces.
Layer 1: The VPC and Its CIDR Block
When you create a VPC, you choose an IP range in CIDR notation, such as
10.0.0.0/16 . The number after the slash tells you how large the range is: a /16 gives roughly 65,000 addresses, a /24 gives 256.Beginner insight: plan your ranges before you build. If two VPCs (or a VPC and your office network) use overlapping CIDR blocks, you won’t be able to connect them later without painful rework. A little planning now prevents a migration later.
Every AWS account also comes with a default VPC in each Region, which is why your first instance “just works” with internet access. For anything beyond experiments, create your own VPC so you control the design.
Layer 2: Subnets, Public vs. Private
A VPC is divided into subnets, and each subnet lives in a single Availability Zone. To build for resilience, spread your resources across subnets in at least two AZs.
Here’s the part that surprises many people: there’s no “public” checkbox on a subnet. A subnet is public simply because its route table sends internet-bound traffic to an internet gateway. A subnet without that route is private.
- Public subnet: holds things that must be reachable from the internet, such as load balancers.
- Private subnet: holds things that should not be, such as application servers and databases.
For a resource in a public subnet to be reachable, it also needs a public IP address and security group rules that allow the traffic. All three must line up.
Beginner insight: AWS reserves five IP addresses in every subnet, so a
/24 gives you 251 usable addresses, not 256.Layer 3: Route Tables and Gateways
A route table is a list of rules: “traffic for this destination goes to that target.” Each subnet is associated with one.
- Local route: automatically present, letting resources inside the VPC talk to each other.
- Internet gateway (IGW): enables two-way internet access for resources with public IPs.
- NAT gateway: lets resources in a private subnet make outbound connections (for software updates, say) without being reachable from the internet. It sits in a public subnet.
Cost insight: NAT gateways are convenient but billed per hour plus per gigabyte of data processed, and they’re a classic source of surprise bills. Check current pricing for your Region, and don’t leave unneeded ones running.
Layer 4: Security Groups vs. Network ACLs
AWS gives you two filtering layers, and mixing them up is one of the most common beginner stumbles.
| Security Group | Network ACL |
|---|---|---|
Applies to | Instance or network interface | Entire subnet |
State | Stateful (return traffic automatically allowed) | Stateless (you must allow return traffic explicitly) |
Rules | Allow only | Allow and deny |
Evaluation | All rules considered together | Rules processed in numbered order |
In practice: security groups do most of the work. A solid pattern is to let your web tier’s security group accept traffic from the internet, let the app tier accept traffic only from the web tier’s security group, and let the database accept traffic only from the app tier’s. Referencing security groups instead of IP addresses keeps rules accurate as instances come and go. Use network ACLs as an additional, coarser layer, for example to block a specific range of addresses.
Layer 5: Keeping Traffic Off the Internet
Here’s an insight that many tutorials skip: resources in a private subnet often need to reach AWS services like S3, and by default that traffic may travel via a NAT gateway and out to the public service endpoint.
VPC endpoints solve this by creating a private path to AWS services:
- Gateway endpoints (for S3 and DynamoDB) are added as route table entries and carry no additional charge.
- Interface endpoints (powered by AWS PrivateLink) cover many other services and are billed hourly plus data processed.
Using an S3 gateway endpoint can improve security and reduce NAT gateway data charges at the same time, which makes it one of the highest-value changes you can make to a private network.
Layer 6: Connecting Networks
As you grow, you’ll need to connect VPCs to each other or to your own data center:
- VPC peering: a direct connection between two VPCs. It’s non-transitive, meaning if A peers with B and B peers with C, A still can’t reach C through B.
- AWS Transit Gateway: a central hub that connects many VPCs and on-premises networks, avoiding a tangle of individual peering links.
- Site-to-Site VPN and Direct Connect: encrypted internet-based and dedicated private connections to on-premises networks.
A Typical Three-Tier Design
Put the pieces together and you get the classic pattern:
- Public subnets (in two AZs) host an Application Load Balancer.
- Private app subnets host EC2 instances that receive traffic only from the load balancer.
- Private database subnets host the database, reachable only from the app tier.
- A NAT gateway (or endpoints) handles outbound needs from the private tiers.
Each layer exposes only what the layer above it needs, which is the core idea of defense in depth.
Five Habits That Pay Off
- Choose non-overlapping CIDR ranges and leave room to grow.
- Spread subnets across multiple Availability Zones.
- Keep databases and app servers in private subnets.
- Chain security groups by reference rather than using wide IP ranges.
- Use VPC endpoints for S3 and DynamoDB, and enable VPC Flow Logs so you can see and troubleshoot traffic.
Troubleshooting Cheat Sheet
When something can’t connect, check in this order:
- Does the route table have a path to the destination?
- Does the security group allow the port and source?
- Does the network ACL allow traffic in and back out?
- Does the instance have a public IP (if internet access is expected)?
- For private resources, is a NAT gateway or endpoint in place?
The VPC Reachability Analyzer can trace these checks for you and point to the exact blocking component.
Keep Learning
Networking clicks fastest when you build it yourself. Create a VPC with two public and two private subnets, launch an instance in each, and try to make one reach the other, then deliberately break a route and use Reachability Analyzer to find it. Pair that with the networking modules in the AWS Skill Builder learning plans for Cloud Practitioner and Solutions Architect.
What was your hardest “why can’t it connect?” moment on AWS? Share it in the comments and how you solved it.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article