
Understanding VPC, Subnets, Route Tables and Internet Gateways on AWS
New to AWS networking? Learn how VPCs, public and private subnets, route tables, and Internet Gateways work together. Explore a simple AWS network architecture and understand the fundamentals of building secure cloud environments.
Series: AWS in the Real World: Building, Securing & Optimizing the Cloud (6 articles)
- …
- 5Understanding VPC, Subnets, Route Tables and Internet Gateways on AWS This article
Understanding VPC, Subnets, Route Tables and Internet Gateways on AWS
Introduction
When building an application on AWS, deploying services such as EC2, RDS, and Application Load Balancers is only part of the job.
You also need to understand how these services communicate with each other and how to control network access.
This is where AWS networking comes in.
One of the most important networking services in AWS is Amazon Virtual Private Cloud (VPC).
A VPC allows you to create a logically isolated network for your AWS resources. Within that network, you can organize resources into subnets, control traffic using route tables, and connect your network to the internet using an Internet Gateway.
In this article, we'll explore four important AWS networking concepts:
- Amazon VPC
- Subnets
- Route Tables
- Internet Gateways
Let's understand how they work together.
1. What Is an Amazon VPC?
Amazon Virtual Private Cloud (VPC) allows you to create a private, logically isolated network within AWS.
Think of a VPC as your own network environment in the AWS cloud.
When you launch resources such as EC2 instances, you can place them inside a VPC and control how they communicate.
For example, imagine you're hosting an online shopping application.
You might want:
- A public-facing load balancer that receives requests from the internet.
- Application servers that process requests.
- A database that stores customer and order information.
You don't want every resource to be directly accessible from the internet.
A VPC helps you organize these resources and control network traffic.
Important things to know about a VPC:
- A VPC belongs to a specific AWS Region.
- You choose an IP address range for your VPC using a CIDR block.
- You can create multiple subnets inside a VPC.
- You can control network traffic using route tables and security groups.
- A VPC can connect to the internet through an Internet Gateway when configured appropriately.
2. What Are Subnets?
A subnet is a smaller network segment inside your VPC.
When creating a VPC, you choose an IP address range. You can divide that range into smaller sections called subnets.
For example, imagine your VPC uses this IP address range:
10.0.0.0/16 You could divide it into smaller subnet ranges:
-
10.0.1.0/24
-
10.0.2.0/24
-
10.0.3.0/24
Each subnet uses part of the VPC's available IP address range.
In AWS, every subnet belongs to one Availability Zone.
There are two common subnet types you'll hear about.
Public Subnet
A public subnet is a subnet whose associated route table has a route to an Internet Gateway.
Resources in a public subnet can communicate with the internet when they also have the required public IP addressing and security configuration.
For example, you might place an internet-facing Application Load Balancer in public subnets.
Private Subnet
A private subnet does not have a direct route to an Internet Gateway.
Resources placed here are not directly reachable from the public internet through an Internet Gateway.
For example, you might place:
- Application servers in private subnets.
- Database instances in private subnets.
This helps reduce direct internet exposure.
Beginner tip: A subnet is not automatically public just because you call it a public subnet. Its route table determines whether it has a route to an Internet Gateway.
3. What Is a Route Table?
A route table is a set of rules that determines where network traffic should go.
Think of it like a navigation system.
When traffic leaves a subnet, the route table helps decide its destination.
For example, a route table might contain:
Destination | Target |
|---|---|
10.0.0.0/16 | Local |
0.0.0.0/0 | Internet Gateway |
Let's understand these entries.
10.0.0.0/16 → Local
This route allows communication within the VPC's IP address range.
AWS automatically creates this local route for a VPC.
0.0.0.0/0 → Internet Gateway
This route sends traffic destined for other IPv4 addresses toward the Internet Gateway.
It is commonly used in a public subnet's route table.
A private subnet generally does not have this direct Internet Gateway route.
You can associate different route tables with different subnets to control how traffic flows.
4. What Is an Internet Gateway?
An Internet Gateway (IGW) is a VPC component that allows communication between resources in your VPC and the internet.
However, simply creating an Internet Gateway does not automatically make every resource accessible from the internet.
You need to configure several things:
- Create an Internet Gateway.
- Attach it to your VPC.
- Add a route to the Internet Gateway in the appropriate subnet's route table.
- Make sure the resource has suitable public IP addressing.
- Configure security groups and network access rules appropriately.
For example, an EC2 instance in a public subnet may need a public IPv4 address to communicate directly with the internet through an Internet Gateway.
A resource in a private subnet does not become publicly accessible just because the VPC has an Internet Gateway attached.
This distinction is important when designing secure AWS environments.
5. How These Components Work Together
Let's connect everything with a practical example.
Imagine you're deploying the same online shopping application from our previous article.
Your AWS environment could look like this:
- VPC: Provides the isolated network for your application.
- Public subnets: Host an internet-facing Application Load Balancer.
- Private application subnets: Host EC2 instances running your application.
- Private database subnets: Host Amazon RDS.
- Route tables: Control where traffic from each subnet is directed.
- Internet Gateway: Provides internet connectivity to appropriately configured public resources.
When a customer visits your website:
- The request comes from the internet.
- The Internet Gateway provides the network path to the public-facing load balancer.
- The load balancer forwards the request to an application server.
- The application server communicates with the database when necessary.
- The application returns the result to the user.
The database does not need to be directly exposed to the internet.
6. A Simple AWS VPC Architecture Diagram
Here's a simplified example of how these networking components fit together:
INTERNET | | INTERNET GATEWAY | | +-------------------+ | AWS VPC | | 10.0.0.0/16 | | | | PUBLIC SUBNET | | 10.0.1.0/24 | | | | Application | | Load Balancer | | | | |---------|---------| | | | | PRIVATE SUBNET | | 10.0.2.0/24 | | | | EC2 Instances | | | | |---------|---------| | | | | DATABASE SUBNET | | 10.0.3.0/24 | | | | Amazon RDS | | | +-------------------+
Understanding the diagram:
- The VPC provides the overall network environment.
- The public subnet contains the internet-facing load balancer.
- The private subnet contains application servers.
- The database subnet contains Amazon RDS.
- The Internet Gateway provides internet connectivity to appropriately configured public resources.
This is a conceptual diagram. A real deployment should use multiple Availability Zones for important application components, and the database should generally use a properly configured DB subnet group.
7. What About Internet Access From Private Subnets?
You might have a question:
If an EC2 instance is inside a private subnet, how can it download software updates or access external services?
One common AWS solution is a NAT Gateway.
A NAT Gateway allows resources in private subnets to initiate connections to the internet without allowing unsolicited internet connections to reach those resources directly.
For example:
- An EC2 instance in a private subnet can download software updates.
- The instance can access certain external services.
- External systems cannot initiate a new connection directly to that instance through the NAT Gateway.
A NAT Gateway is commonly placed in a public subnet and uses an Internet Gateway for internet connectivity.
Important: NAT Gateways have hourly and data-processing charges. Consider the cost before using one, especially in learning environments.
You don't need to configure a NAT Gateway in every AWS project. It depends on whether your private resources need outbound internet access.
8. Security Best Practices for AWS Networking
When designing your VPC, keep these practices in mind:
1. Keep databases private
Avoid placing databases in public subnets or exposing database ports to the internet.
2. Use security groups
Allow only the network traffic required by your application.
For example, the database security group should allow database connections from the application servers' security group rather than from the entire internet.
3. Separate application and database resources
Use different subnets to organize resources based on their responsibilities.
4. Restrict unnecessary internet access
Only expose resources that genuinely need to receive internet traffic.
5. Plan your IP address ranges
Choose VPC and subnet CIDR ranges carefully to avoid overlapping address ranges with networks you may connect later.
6. Monitor network activity
Use AWS monitoring and logging capabilities to understand network traffic and investigate unexpected activity.
9. What Should Beginners Learn Next?
If you're starting with AWS networking, focus on understanding these concepts first:
- What is an IP address and CIDR block?
- What is the difference between a VPC and a subnet?
- How does a route table work?
- What is the purpose of an Internet Gateway?
- What makes a subnet public or private?
- How does a NAT Gateway work?
- How do security groups control network traffic?
Once you understand these fundamentals, building AWS network architectures becomes much easier.
Final Thoughts
AWS networking might seem complicated when you're first starting out, but the fundamentals are easier to understand when you break them down.
Remember:
- VPC: Your isolated network environment in AWS.
- Subnets: Smaller network sections inside your VPC.
- Route tables: Rules that determine where network traffic goes.
- Internet Gateway: A component that enables communication between a VPC and the internet.
These components work together to help you build secure and organized cloud environments.
If you're learning AWS, take time to understand networking before deploying complex applications. It will make a big difference when you start working with real-world architectures.
What about you?
Have you created your first AWS VPC yet? Which networking concept do you find most confusing: subnets, route tables, Internet Gateways, or NAT Gateways?
Share your experience in the comments!
Coming Next: Deploying a Web Application Using EC2 and Application Load Balancer — putting AWS networking concepts into practice with a real application.
Series: AWS in the Real World: Building, Securing & Optimizing the Cloud (6 articles)
- …
- 5Understanding VPC, Subnets, Route Tables and Internet Gateways on AWS This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article