
AWS VPC Explained Through Traffic Flow: From Internet Requests to Private Resources
An Amazon VPC is more than an isolated network. It determines how traffic reaches your application, how services communicate, and which resources should remain private. Follow a practical three-tier AWS architecture to understand subnets, route tables, Internet Gateways, NAT Gateways, Security Groups, and common networking mistakes.
Introduction: What actually happens when a request reaches AWS?
Imagine opening a website hosted on AWS.
You enter the URL, your browser sends a request, and the application returns a response. From the user's perspective, it looks straightforward. Behind the scenes, however, several networking components may be involved.
The request might reach a load balancer in a public subnet, travel to an application server in a private subnet, and then reach a database that should never be directly exposed to the internet.
How does AWS decide where that traffic goes? And how does it prevent someone from connecting directly to a resource that should remain private?
This is where Amazon Virtual Private Cloud (Amazon VPC) becomes important.
While learning AWS, I found it more useful to understand how the components work together rather than memorizing their definitions individually. In this article, I'll use a practical application architecture to explain how VPC networking works and where security controls fit into the traffic flow.
1. Start with the network: What is a VPC?
An Amazon VPC is a logically isolated virtual network in which you launch AWS resources.
When creating a VPC, you choose an IP address range and configure the network components needed by your workload. You can create subnets, associate route tables, attach gateways, and apply network security controls.
For example, consider a VPC with this IPv4 CIDR block:
10.0.0.0/16 We can divide that address range into smaller subnets for different application components.
VPC: 10.0.0.0/16|+-- Public Subnet A| +-- 10.0.1.0/24| +-- Application Load Balancer|+-- Private Application Subnet A| +-- 10.0.11.0/24| +-- Application Server|+-- Private Database Subnet A| +-- 10.0.21.0/24| +-- Database|+-- Additional subnets in another Availability ZoneThese CIDR ranges are illustrative. In a real design, make sure the VPC and subnet address ranges do not overlap with networks that need to communicate with them.
The main idea is to separate resources according to their purpose and exposure requirements.
A load balancer may need to accept requests from the internet. An application server may only need requests from that load balancer. A database may only need connections from the application layer.
That separation gives us a foundation for controlling traffic.
2. Public and private subnets: The difference is routing
A common misconception is that a subnet becomes public simply because an EC2 instance inside it has a public IP address.
That's not how it works.
A subnet is generally considered public when its associated route table has a route to an Internet Gateway. A private subnet does not have a direct route to an Internet Gateway.
Let's compare them.
Public subnet | Private subnet |
|---|---|
Has a route to an Internet Gateway | Has no direct route to an Internet Gateway |
Can host internet-facing resources | Commonly hosts application servers and databases |
Resources need suitable addressing and security rules for internet connectivity | Resources are not directly reachable from the internet through an ordinary public IPv4 route |
May host a public load balancer or NAT Gateway | May use a NAT Gateway or VPC endpoint for specific outbound connectivity |
The word public does not mean every resource in that subnet is automatically accessible to everyone. Routing, addressing, security groups, network ACLs, and other applicable controls still matter.
For a typical web application, I would place the internet-facing load balancer in public subnets and keep the application servers and database in private subnets.
This reduces direct exposure of the components that do not need to accept internet connections.
3. Internet Gateway: Connecting a VPC to the internet
An Internet Gateway (IGW) provides a connection between a VPC and the internet.
However, attaching an Internet Gateway alone does not make every resource in the VPC internet-accessible. The relevant subnet also needs the correct route, and a resource needs suitable addressing and security rules.
For example, a public subnet's route table might contain:
Destination | Target |
|---|---|
10.0.0.0/16 | local |
0.0.0.0/0 | Internet Gateway |
The first route is the VPC's local route. It supports routing between resources within the VPC's address range, subject to other applicable network controls.
The second route directs IPv4 traffic destined for addresses outside the VPC's CIDR range toward the Internet Gateway.
For an EC2 instance to communicate directly with the public IPv4 internet, it also needs appropriate public IPv4 addressing, and the relevant security controls must permit the traffic.
This is why troubleshooting internet connectivity requires checking more than whether an Internet Gateway exists.
Practical lesson: A gateway creates a possible network path, but the route table and other configuration determine how that path can be used.
4. Route tables: Where should the traffic go?
Think of a route table as a set of directions for network traffic.
Each subnet is associated with a route table, either explicitly or through the VPC's main route table. The routes determine which target receives traffic for a particular destination.
For our example, we can use different route tables for the public and private subnets.
Public route table
Destination | Target |
|---|---|
10.0.0.0/16 | local |
0.0.0.0/0 | Internet Gateway |
Private application route table
Destination | Target |
|---|---|
10.0.0.0/16 | local |
0.0.0.0/0 | NAT Gateway, if outbound internet access is required |
The local route allows traffic to be routed within the VPC. The default route sends other IPv4 traffic to the configured target.
The private route table shown above is an example for an application that needs outbound internet access. If the application doesn't need that connectivity, you may not need the default route to a NAT Gateway at all.
A route table can also direct traffic to other targets, such as a VPC endpoint, VPN connection, or Transit Gateway, depending on the architecture.
The important point is that routes should reflect the connectivity the application actually needs.
5. NAT Gateway: Outbound access without direct inbound exposure
Suppose an application server is in a private subnet. It needs to download software updates or call an external API, but it shouldn't be directly accessible from the internet.
A NAT Gateway can provide outbound internet connectivity for this type of IPv4 use case.
A typical traffic path looks like this:
Private Application Server | vPrivate Route Table | vNAT Gateway(in a public subnet) | vInternet Gateway | vInternetThe NAT Gateway is deployed in a public subnet, and that subnet needs a suitable route to the Internet Gateway. The private subnet's route table directs internet-bound traffic to the NAT Gateway.
The private server can initiate an outbound connection, while unsolicited inbound internet connections cannot normally be initiated directly to that private server through the NAT Gateway.
There are a few practical details worth remembering:
- A NAT Gateway does not replace Security Groups or other network controls.
- A public NAT Gateway is commonly used for outbound IPv4 internet access.
- NAT Gateways incur charges, so consider the cost before adding one to a small learning environment.
- For supported AWS services, a VPC endpoint may provide private connectivity without requiring a NAT Gateway or Internet Gateway path.
For a small lab, don't create a NAT Gateway automatically just because it appears in a standard architecture diagram. First decide whether outbound internet access is actually necessary.
6. Security Groups and Network ACLs: Routing isn't permission
This is one of the most important distinctions in VPC networking.
A route table determines where traffic should go. It does not, by itself, grant permission to communicate.
Security Groups and Network Access Control Lists (network ACLs) provide additional network traffic controls.
Security Groups
Security Groups act as virtual firewalls for supported resources, such as EC2 network interfaces.
They support allow rules for inbound and outbound traffic and are stateful. If traffic is permitted and a connection is established, response traffic is handled automatically by the stateful rules.
For our three-tier application, we might configure:
- Load balancer Security Group: Allow inbound HTTPS on port
443from intended client networks.
- Application Security Group: Allow the application's listening port only from the load balancer's Security Group.
- Database Security Group: Allow the database port only from the application Security Group.
For example, if the application uses PostgreSQL, the database Security Group might allow inbound TCP port
5432 from the application Security Group rather than from the entire internet.This establishes a clear relationship between the application layers.
Network ACLs
Network ACLs operate at the subnet level. Unlike Security Groups, they are stateless, support both allow and deny rules, and evaluate rules in ascending rule-number order.
Because they are stateless, the inbound and outbound rules must account for both directions of traffic, including applicable return traffic and ephemeral ports.
Feature | Security Group | Network ACL |
|---|---|---|
Applies to | Network interfaces/resources | Subnets |
Rules | Allow rules | Allow and deny rules |
Connection tracking | Stateful | Stateless |
Return traffic | Automatically handled for allowed connections | Must be permitted by the applicable rules |
In many architectures, Security Groups are the primary workload-level network control. Network ACLs can provide an additional subnet-level layer where there is a clear reason to use them.
Avoid adding complex NACL rules without understanding their effect. An incorrect stateless rule can block return traffic even when the original request appears to be allowed.
7. Follow a real request through the architecture
Let's put these components together.
Imagine a user opens an HTTPS website hosted in AWS.
User's Browser | | HTTPS :443 vInternet Gateway | vPublic Application Load Balancer | | Application traffic vPrivate Application Server | | Database connection vPrivate DatabaseThis is a simplified illustration of a possible three-tier architecture. In production, the load balancer and application servers would typically be deployed across multiple Availability Zones for availability.
Here's how the request moves:
Step 1: The user sends a request.
The browser connects to the public endpoint of the load balancer using HTTPS.
Step 2: The network path is established.
The load balancer's public subnets have suitable routing, addressing, and security configuration. The Internet Gateway provides the internet connectivity path.
Step 3: The load balancer forwards the request.
The load balancer sends the request to a healthy application target. The application server's Security Group permits the required traffic from the load balancer's Security Group.
Step 4: The application accesses the database.
If the request requires stored data, the application connects to the database using the configured database port. The database Security Group permits connections from the application layer, not from arbitrary internet clients.
Step 5: The response returns.
The response travels back through the established connections, subject to the applicable routing and network controls.
Notice what we didn't do: we didn't make the database publicly accessible just to let the application reach it.
The application can communicate with the database through the VPC's local routing while Security Groups restrict which resources can connect.
That is the value of designing the network around actual traffic requirements.
8. Common VPC mistakes that cause problems
Here are some mistakes worth checking when building or troubleshooting an AWS project.
Mistake 1: Assuming an Internet Gateway makes every resource public
An Internet Gateway does not automatically provide internet connectivity to every subnet or instance. Check the subnet's route table, public addressing, and security rules.
Mistake 2: Opening SSH or RDP to the entire internet
Allowing administrative ports from
0.0.0.0/0 unnecessarily increases exposure. Prefer controlled administration paths, such as AWS Systems Manager Session Manager where supported and appropriately configured, or narrowly restricted source addresses when direct access is required.Mistake 3: Confusing routing with permission
A valid route does not mean a connection is allowed. Security Groups, network ACLs, and other applicable controls can still block traffic.
Mistake 4: Making a database publicly accessible to solve a connectivity problem
If an application server cannot connect to its database, investigate the route, port, Security Groups, network ACLs, and database configuration. Public exposure is rarely the right first fix.
Mistake 5: Creating NAT Gateways without considering cost
NAT Gateways can be useful, but they incur charges. For learning projects, understand whether you need outbound internet access and explore suitable VPC endpoints or other alternatives when appropriate.
Mistake 6: Forgetting Availability Zones
Deploying all components in a single Availability Zone can increase the impact of an Availability Zone disruption. Production architectures commonly distribute appropriate resources across multiple Availability Zones.
9. A practical checklist for your next VPC project
Before considering a VPC design ready, check the following:
- Choose a VPC CIDR range that avoids conflicts with connected networks.
- Divide the network into subnets according to workload and exposure requirements.
- Put internet-facing resources in appropriately configured public subnets.
- Keep application servers and databases private when direct internet access is unnecessary.
- Verify the route table associated with each subnet.
- Confirm that Internet Gateway and NAT Gateway routes are correct where needed.
- Restrict Security Group rules to the required ports and trusted sources.
- Review NACL rules if they are being used as an additional control.
- Consider VPC endpoints for supported AWS services when private connectivity is useful.
- Review cost, logging, and availability requirements before deploying.
For troubleshooting, follow the traffic path one step at a time. Start with the source and destination, check the route tables, verify the relevant Security Groups and NACLs, and then inspect the service configuration.
AWS VPC Reachability Analyzer can also help analyze whether a network path is possible between supported endpoints. VPC Flow Logs can provide useful information about IP traffic to and from VPC network interfaces, subnets, or VPCs.
Final thoughts
The biggest lesson I take from learning VPC networking is that connectivity and security cannot be designed separately.
A route table helps determine where traffic goes. A Security Group helps determine which traffic is permitted. Public and private subnet design helps establish which resources should be exposed and which should remain internal.
Once these responsibilities become clear, AWS networking becomes much easier to reason about and troubleshoot.
My recommendation for anyone learning AWS is to build a small VPC, create separate public and private subnets, inspect the route tables, and test how traffic behaves when a rule or route changes. A small lab can make these concepts much easier to understand than memorizing definitions alone.
Question for the community: When troubleshooting an AWS connectivity issue, what do you check first: the route table, Security Group, or network ACL—and why?
References
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article