AWS VPC Explained: A Practical Guide to Building Your First Network
Learn how Amazon VPC works by understanding VPCs, subnets, route tables, internet gateways, security groups, and network ACLs, with a practical approach to designing a secure AWS network.
AWS VPC Explained: A Practical Guide to Building Your First Network
When working with AWS, one of the first services you should understand is Amazon Virtual Private Cloud (Amazon VPC).
A VPC allows you to create a logically isolated network in AWS where you can launch and manage resources such as EC2 instances. If you already have experience with traditional networking, many VPC concepts will feel familiar, but AWS introduces its own way of designing and securing networks.
In this article, we will look at the key components of a VPC and how they work together.
What Is an Amazon VPC?
An Amazon VPC is a virtual network that you define within the AWS Cloud.
You can choose:
- The IPv4 CIDR block
- Subnets
- Availability Zones
- Route tables
- Internet connectivity
- Network security controls
For example, you could create a VPC using:
VPC: 10.0.0.0/16
This provides a private address space that can be divided into smaller subnets.
Understanding Subnets
A subnet is a range of IP addresses inside a VPC.
For example:
VPC: 10.0.0.0/16
Public Subnet:10.0.1.0/24
Private Subnet:10.0.2.0/24
A common architecture is to place public-facing resources in public subnets while keeping internal resources in private subnets.
A subnet belongs to a specific Availability Zone.
For example:
AWS Region | +-----------+-----------+ | | AZ-1a AZ-1b | | Public Subnet Public Subnet10.0.1.0/24 10.0.3.0/24 | | Private Subnet Private Subnet10.0.2.0/24 10.0.4.0/24
Using multiple Availability Zones can help improve application availability and resilience.
What Makes a Subnet Public?
A subnet is commonly considered public when its associated route table contains a route to an Internet Gateway.
For example:
Destination Target
10.0.0.0/16 local0.0.0.0/0 Internet Gateway
The
0.0.0.0/0 route represents destinations outside the VPC.However, having a route to an Internet Gateway alone does not automatically make an EC2 instance reachable from the internet. The instance also needs appropriate networking configuration, such as a public IPv4 address, and security controls must allow the traffic.
Internet Gateway
An Internet Gateway (IGW) provides a path between a VPC and the internet.
A simplified traffic flow could look like this:
Internet |Internet Gateway |Route Table |Public Subnet |EC2 Instance
The Internet Gateway is attached to the VPC.
Route Tables
Route tables determine where network traffic is directed.
For example:
Destination Target--------------------------------10.0.0.0/16 local0.0.0.0/0 igw-xxxxxxxx
The first route allows communication within the VPC.
The second route sends internet-bound traffic toward the Internet Gateway.
Understanding route tables is extremely important when troubleshooting AWS connectivity.
If an instance cannot reach another network, one of the first things to check is whether the required route exists.
Security Groups
Security Groups act as a virtual firewall for resources such as EC2 instances.
They control traffic using rules based on parameters such as:
- Protocol
- Port
- Source or destination
For example, an EC2 web server might have:
Inbound:TCP 80 -> Web trafficTCP 443 -> HTTPS trafficTCP 22 -> SSH from an authorized IP
Security Groups are stateful, meaning the response traffic is automatically allowed when the corresponding request is permitted.
A good security practice is to allow only the traffic that is actually required.
Network ACLs
Network ACLs, or NACLs, provide another layer of network traffic control at the subnet level.
Unlike Security Groups, NACLs are stateless.
This means inbound and outbound traffic must be considered separately.
For example:
Internet |NACL |Subnet |Security Group |EC2
Security Groups and NACLs serve different purposes and can work together as layers of defense.
Public vs Private Subnets
A typical three-tier architecture might look like this:
Internet | Internet GW | Public Subnet | Load Balancer | Private Subnet | Application EC2 | Private Subnet | Database
The idea is to avoid exposing internal resources directly to the internet.
For example, a database normally does not need a public IP address. It can remain in a private subnet while application servers communicate with it internally.
NAT Gateway
Private resources may still need outbound internet access for tasks such as downloading updates.
A NAT Gateway can provide outbound internet connectivity for resources in private subnets without requiring those resources to have public IP addresses.
A simplified design is:
Private EC2 |Private Route Table |NAT Gateway |Internet Gateway |Internet
The NAT Gateway is placed in a public subnet.
A Simple VPC Design
Let's put the concepts together.
VPC: 10.0.0.0/16|+-- Public Subnet 10.0.1.0/24| || +-- Load Balancer| +-- NAT Gateway|+-- Private Subnet 10.0.2.0/24| || +-- Application Server|+-- Private Subnet 10.0.3.0/24 | +-- Database
The public subnet has internet connectivity through the Internet Gateway.
The application and database resources remain in private subnets.
The application subnet can use the NAT Gateway when outbound internet access is required.
Troubleshooting VPC Connectivity
When troubleshooting an AWS networking problem, don't immediately assume the issue is the Security Group.
A useful troubleshooting sequence is:
- Check the resource's IP configuration.
- Check the subnet.
- Check the associated route table.
- Check the Internet Gateway or NAT Gateway.
- Check Security Group rules.
- Check Network ACL rules.
- Check DNS configuration where applicable.
- Check whether the destination is reachable and listening on the expected port.
For example, if an EC2 instance in a private subnet cannot access the internet, investigate:
EC2 ↓Subnet ↓Route Table ↓NAT Gateway ↓Public Subnet ↓Internet Gateway ↓Internet
Finding where the traffic stops is often more effective than changing multiple settings at once.
Security Best Practices
When designing a VPC, security should be considered from the beginning.
Some useful practices include:
- Avoid unnecessary public IP addresses.
- Keep databases in private subnets.
- Follow the principle of least privilege for Security Groups.
- Restrict SSH access to trusted sources.
- Use HTTPS for web applications.
- Separate application tiers using subnets and security controls.
- Monitor network and API activity using appropriate AWS services.
- Use multiple Availability Zones when high availability is required.
Conclusion
Amazon VPC provides the foundation for networking in AWS.
The most important concepts to understand are:
VPC ├── Subnets ├── Route Tables ├── Internet Gateway ├── NAT Gateway ├── Security Groups └── Network ACLs
Once these concepts are clear, you can move toward more advanced AWS networking topics such as VPC Peering, Transit Gateway, Site-to-Site VPN, hybrid networking, Route 53, and centralized network security.
The best way to learn these concepts is to build them yourself. Create a VPC, configure the subnets and routes, launch resources, test connectivity, intentionally introduce a configuration problem, and then troubleshoot it.
That hands-on experience is where AWS networking really starts to make sense.
#amazon-vpc#aws-networking#aws-cloudformation#aws-identity-and-access-management#aws-network-firewall
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article