AWS Builder Center
AWS VPC Networking Explained: Public vs. Private Subnets, Route Tables, and Security

AWS VPC Networking Explained: Public vs. Private Subnets, Route Tables, and Security

How does traffic actually move inside AWS? Explore VPCs, CIDR blocks, public and private subnets, Internet Gateways, NAT Gateways, route tables, Security Groups, and Network ACLs through practical architecture examples and real-world troubleshooting scenarios.

student

AWS VPC Networking Explained: Public vs. Private Subnets, Route Tables, and Security

Imagine launching an EC2 instance on AWS. The instance is running, its status checks are successful, and your application is deployed. But when you try to access it, the connection times out.
What went wrong?
It could be a missing route, an incorrectly configured security group, a missing Internet Gateway, or an issue with the subnet configuration.
This is where understanding Amazon VPC becomes essential.
Networking is one of the most important foundations of cloud computing. Whether you are deploying a simple website, building a backend application, or designing a production environment, understanding how resources communicate securely will make you a much better cloud engineer.
In this article, we will explore Amazon VPC from the fundamentals to a practical three-tier architecture.

1. What Is Amazon VPC?

Amazon Virtual Private Cloud (VPC) allows you to create a logically isolated virtual network inside AWS.
Think of a VPC as your own private network in the cloud. You control its IP address ranges, subnets, routing, and network access.
Within a VPC, you can deploy resources such as:
  • Amazon EC2 instances
  • Application Load Balancers
  • Amazon RDS databases
  • NAT Gateways
  • Network interfaces
  • Other supported AWS networking resources
For example, an organization might create a VPC for its web application and separate its frontend-facing components, application servers, and database resources into different network segments.
This makes it easier to manage connectivity and apply security controls.
One important detail: a VPC belongs to an AWS Region and can span multiple Availability Zones, but an individual subnet exists entirely within one Availability Zone.

2. Understand CIDR Blocks and IP Addressing

Before creating a VPC, you need to understand how IP addresses are allocated.
AWS uses CIDR notation to define IP address ranges.
For example:
 10.0.0.0/16 
This represents a network containing 65,536 IPv4 addresses.
A smaller network might be:
 10.0.1.0/24 
This represents 256 IPv4 addresses before accounting for AWS-reserved addresses.
Consider this example network:
VPC CIDR:  10.0.0.0/16 
Subnet
CIDR block
Purpose
Public Subnet A
10.0.1.0/24
Public-facing resources
Public Subnet B
10.0.2.0/24
Public-facing resources
Private App A
10.0.11.0/24
Application servers
Private App B
10.0.12.0/24
Application servers
Private DB A
10.0.21.0/24
Database resources
Private DB B
10.0.22.0/24
Database resources
This is an illustrative address plan, not a mandatory AWS configuration.
Good CIDR planning matters because overlapping IP ranges can create connectivity problems when connecting multiple VPCs or integrating with on-premises networks.
Remember: Choose address ranges carefully before deploying resources. Changing an existing network design later can be difficult.

3. Public Subnet vs. Private Subnet

This is one of the most important concepts in AWS networking.

Public Subnet

A public subnet is a subnet whose associated route table has a route to an Internet Gateway.
For a typical IPv4 configuration, the route looks like this:
 0.0.0.0/0 → Internet Gateway 
Resources that need direct IPv4 internet connectivity must also have an appropriate public IPv4 address or Elastic IP address and suitable network permissions.
Common uses include:
  • Internet-facing Application Load Balancers
  • Bastion hosts, where justified
  • NAT Gateways

Private Subnet

A private subnet does not have a direct route to an Internet Gateway.
It is commonly used for:
  • Backend application servers
  • Internal services
  • Database resources
  • Private workloads that should not accept direct internet connections
A private subnet can still communicate with other resources inside the VPC through appropriate local routes and can access external networks through a NAT Gateway or other configured connectivity mechanism.

The key difference

Feature
Public Subnet
Private Subnet
Direct route to IGW
Yes
No
Direct internet connectivity
Possible with the required addressing and rules
No direct IGW path
Common resources
Public Load Balancer
Application servers
Security approach
Restrict public access carefully
Keep resources private
A common misconception is that creating a subnet and naming it Public automatically makes it public.
That is incorrect.
Its routing configuration determines whether the subnet is public or private.

4. What Is an Internet Gateway?

An Internet Gateway (IGW) is a VPC component that enables communication between your VPC and the internet.
To use one:
  1. Create an Internet Gateway.
  1. Attach it to your VPC.
  1. Open the route table associated with your public subnet.
  1. Add a default IPv4 route:
 0.0.0.0/0 → igw-xxxxxxxx 
  1. Ensure the resource has the necessary public addressing and security rules.
The Internet Gateway provides the internet-facing network path. It does not automatically make every resource in your VPC publicly accessible.
Your route tables, IP addresses, security groups, and network ACLs still matter.
For example, an EC2 instance without a public IPv4 address cannot use the conventional direct public IPv4 connectivity path simply because its subnet has an IGW route.

5. What Is a NAT Gateway?

Now consider a different requirement.
Your application server is deployed in a private subnet. It needs to download operating system updates or communicate with an external software repository.
But you do not want to expose the application server directly to the internet.
How can you achieve this?
The answer is a NAT Gateway.
A Network Address Translation (NAT) Gateway allows resources in private subnets to initiate connections to external destinations without allowing unsolicited inbound internet connections to those private resources through that NAT path.

How NAT Gateway works

A typical setup is:
  1. Create a NAT Gateway in a public subnet.
  1. Associate an Elastic IP address where required for the public NAT Gateway configuration.
  1. Ensure the public subnet has a route to the Internet Gateway.
  1. Open the private subnet's route table.
  1. Add this route:
 0.0.0.0/0 → NAT Gateway 
Now, resources in the private subnet can send suitable outbound IPv4 traffic through the NAT Gateway.
The NAT Gateway uses its own public connectivity to communicate with external destinations.

An important cost warning

NAT Gateway is not automatically free.
AWS charges for NAT Gateway availability and data processing, along with applicable data transfer charges.
For learning projects, do not create a NAT Gateway and forget about it. Check regional pricing and delete resources when you have finished using them.
You can also investigate VPC endpoints for private connectivity to supported AWS services. For example, an S3 Gateway Endpoint can help avoid routing S3 traffic through a NAT Gateway.

6. What Are Route Tables?

A route table determines where network traffic from a subnet or gateway should go.
Think of a route table as a traffic controller.
Each route contains:
  • Destination: The IP address range that the route matches.
  • Target: Where the traffic should be sent.
For example:
Destination
Target
10.0.0.0/16
local
0.0.0.0/0
Internet Gateway
This could represent a public subnet route table.
A private subnet might instead have:
Destination
Target
10.0.0.0/16
local
0.0.0.0/0
NAT Gateway
The  local  route allows communication within the VPC's IP address ranges.
AWS selects the most specific matching route when multiple routes match a destination. This is called Longest Prefix Match.
Every subnet must be associated with a route table. If you do not explicitly associate one, the subnet uses the VPC's main route table.
Understanding route tables is critical when troubleshooting connectivity problems.

7. Security Groups vs. Network ACLs

AWS offers two important network security controls: Security Groups and Network Access Control Lists (NACLs).
Although both control network traffic, they operate differently.

Security Groups

Security Groups act as virtual firewalls associated with resources through their network interfaces.
They control inbound and outbound traffic using allow rules.
Important characteristics:
  • Stateful traffic filtering.
  • Allow rules only.
  • Can reference other Security Groups.
  • Return traffic for an allowed connection is automatically permitted.
For example, an application server's Security Group could allow inbound traffic on port 3000 only from the Security Group attached to its load balancer.
This is more controlled than allowing port 3000 from every public IP address.

Network ACLs

Network ACLs operate at the subnet level.
They provide an additional layer of traffic filtering.
Important characteristics:
  • Stateless traffic filtering.
  • Support both allow and deny rules.
  • Inbound and outbound rules are evaluated separately.
  • Rules are evaluated in ascending rule-number order until a matching rule is found.
Because NACLs are stateless, return traffic must also be allowed explicitly.

Comparison

Feature
Security Group
Network ACL
Level
Resource/network interface
Subnet
Stateful or stateless
Stateful
Stateless
Allow rules
Yes
Yes
Deny rules
No
Yes
Return traffic
Automatically allowed
Must be explicitly allowed
Main purpose
Primary resource-level protection
Additional subnet-level protection
For most common application architectures, Security Groups are your primary network access control mechanism. NACLs can provide an additional security layer.

8. Build a Real-World Three-Tier Architecture

Let's combine everything into one practical example.
Imagine you are building an e-commerce application.
It has three major components:
  1. Frontend access for customers.
  1. Backend services that process requests.
  1. A database that stores customer and application information.
A common AWS design could look like this:

Tier 1: Public Sub

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