AWS Builder Center
VPC Deep Dive: Subnets, Route Tables, NACLs, and Secure Cloud Boundarie

VPC Deep Dive: Subnets, Route Tables, NACLs, and Secure Cloud Boundarie

A practical deep dive into AWS VPC networking, covering public and private subnets, route tables, NAT Gateways, Security Groups, and NACLs, with a focus on traffic flow, isolation, defense in depth, and DevSecOps architecture.

VPC Deep Dive: Subnets, Route Tables, NACLs, and Secure Cloud Boundaries

Cloud networking becomes interesting when you stop letting the default configuration make decisions for you.
Most cloud deployments make networking almost invisible.
You open the AWS console, launch an EC2 instance, select a default VPC, assign a public IP, and connect to the server. The interface gives you very little reason to think about what happens behind the scenes.
But underneath that simple experience are several important components:
  • VPCs define the overall network boundary.
  • Subnets divide that network into logical segments.
  • Route tables determine where packets should go.
  • Internet Gateways provide internet connectivity.
  • NAT Gateways provide controlled outbound internet access for private resources.
  • Security Groups provide stateful instance-level filtering.
  • Network Access Control Lists (NACLs) provide stateless subnet-level filtering.
The abstraction is useful.
But it also hides assumptions.
I wanted to understand what happens when those assumptions are removed and the network boundary is designed deliberately instead.
The goal is simple:
Define the boundaries first, control traffic explicitly, isolate workloads, and use multiple layers of security rather than depending on a single firewall mechanism.



Starting With the Network Boundary

A common simplified architecture looks like this:
Internet
↓
Internet Gateway
↓
Route Table
↓
EC2 Instance

It works, but it can make the instance appear to be the center of the architecture.
A more security-oriented design starts somewhere else:
VPC CIDR
↓
Subnet Allocation
↓
NACL Evaluation
↓
Route Designation
↓
Security Group
↓
Workload

The difference is subtle but important.
Instead of asking:
"How do I expose this EC2 instance?"
we ask:
"What network boundary should this workload exist inside?"
That change in thinking affects the entire architecture.
A VPC provides the overall IP address space. Subnets divide that space into logical segments, while route tables determine where traffic can travel.
For example:
VPC: 10.0.0.0/16

├── Public Subnet
│ └── 10.0.1.0/24
│
└── Private Subnet
└── 10.0.2.0/24

The public subnet may contain internet-facing resources such as load balancers.
The private subnet can contain backend applications and databases that should not receive direct inbound internet connections.
This makes the subnet itself part of the security architecture.



Public vs Private Subnets

The terms public subnet and private subnet are often misunderstood.
A subnet is not automatically public simply because it contains an EC2 instance.
The important factor is routing.
A subnet is generally considered public when its associated route table contains a route to an Internet Gateway, for example:
Destination Target

10.0.0.0/16 local
0.0.0.0/0 Internet Gateway

A private subnet does not have a direct route to an Internet Gateway.
Instead, it may use a NAT Gateway for outbound internet access:
Private Instance
↓
Private Route Table
↓
NAT Gateway
↓
Internet Gateway
↓
Internet

This creates an important security property:
The private instance can initiate outbound connections without requiring a publicly reachable IP address.
For example, a backend server may need to download operating-system updates:
Backend Server
↓
NAT Gateway
↓
Internet

But an external system cannot simply initiate a new connection directly to that backend through the NAT Gateway.



Route Tables: The GPS of the VPC

A route table answers one fundamental question:
Where should this packet go?
A basic route table might look like:
Destination Target

10.0.0.0/16 local
0.0.0.0/0 nat-xxxxxxxx

The first route allows communication within the VPC.
The second sends internet-bound traffic toward the NAT Gateway.
This distinction is critical:
Routing determines whether a path exists.
It does not necessarily mean the traffic is allowed.
For example, a database may have a valid route to a web server:
Database
↓
Route Table
↓
Web Server

But a Security Group or NACL can still reject the traffic.
Therefore:
Routable ≠ Allowed

This is one of the most important concepts in VPC security.



Why NACLs Became Interesting

Security Groups are usually the first AWS security mechanism developers learn.
They are powerful because they are stateful.
For example, if an instance allows an outbound HTTPS connection, the response traffic is automatically handled as part of the established connection.
NACLs work differently.
A Network Access Control List is stateless.
That means inbound and outbound traffic are evaluated independently.
This makes NACLs particularly interesting when designing strict subnet boundaries.
Think about the security layers like this:
Internet
↓
NACL
↓
Security Group
↓
Network Interface
↓
EC2 Instance

The NACL operates at the subnet boundary.
The Security Group operates closer to the workload.
This creates defense in depth.



Stateful vs Stateless Security

The distinction becomes clearer with an example.
Suppose a private server wants to access an external HTTPS service.
The server sends:
Source Port: 50000
Destination Port: 443
Protocol: TCP

The outbound NACL must allow the traffic.
The request reaches the external server through the NAT Gateway.
The response comes back.
Because the NACL is stateless, the returning traffic must independently satisfy an inbound rule.
A simplified flow can look like:
Outbound Request
TCP Source: 50000
TCP Destination: 443
↓
NACL Outbound
↓
NAT Gateway
↓
Internet
↓
External Server
↓
Response
↓
NACL Inbound
↓
Private Instance

The return traffic uses an ephemeral port.
A simplified NACL configuration might therefore need to account for ephemeral ports such as:
TCP 1024-65535

However, the exact ephemeral port range can depend on the operating system and networking configuration.
This is where stateless filtering becomes more complex.
A rule that looks perfectly reasonable at first can unintentionally break legitimate return traffic.



The First Real Problem: Finding a Path Out

Consider a simple architecture:
Internet
↑
|
Internet Gateway
|
┌────────┴────────┐
│ │
Public Subnet Private Subnet
│ │
Load Balancer Application
|
Database

The database should not be directly exposed to the internet.
But it may still need internet access for:
  • OS updates
  • Security patches
  • Package downloads
  • External APIs
  • Monitoring services
The solution is generally controlled outbound access through a NAT Gateway:
Private Subnet
↓
Private Route Table
↓
NAT Gateway
↓
Internet Gateway
↓
Internet

This is a good example of why network architecture is more than simply assigning IP addresses.
Removing a public IP does not automatically solve the problem.
It changes the traffic path.



Availability Matters Too

Suppose a private subnet uses a NAT Gateway located in one Availability Zone.
The design may work perfectly.
But what happens if that Availability Zone experiences a failure?
A single NAT Gateway can become a dependency for all private workloads using it.
A more resilient architecture may use multiple Availability Zones and NAT Gateways:
VPC
|
┌────────┴────────┐
│ │
AZ-A AZ-B
│ │
NAT Gateway A NAT Gateway B
│ │
Private Subnet A Private Subnet B

Now routing can be designed so each private subnet primarily uses the NAT Gateway in its own Availability Zone.
This introduces another important principle:
Routing is part of the availability architecture, not just the connectivity architecture.



What Happens When the Perimeter Is Breached?

Now consider a more realistic security scenario.
Suppose an attacker discovers a vulnerability in a web application.
The attacker compromises the web server.
What happens next?
If the web server and database are sitting in the same broadly accessible network segment, the attacker may attempt lateral movement.
Internet
↓
Web Server
↓
Compromised Host
↓
Database

This is where network segmentation becomes valuable.
A better design separates workloads:
Internet
↓
Public Subnet
↓
Load Balancer
↓
Application Subnet
↓
Database Subnet

Each layer can have different routing and access policies.
The goal is not to assume that the application will never be compromised.
The goal is to make compromise less useful to an attacker.
This is the essence of blast-radius reduction.



Strict Egress Filtering

Inbound security gets most of the attention.
Outbound traffic deserves the same consideration.
If a compromised server can communicate freely with the internet, an attacker may attempt:
  • Command-and-control communication
  • Data exfiltration
  • Malware downloads
  • Credential theft
  • Additional payload delivery
Strict outbound controls can reduce these possibilities.
For example:
Application Server
↓
Allowed HTTPS
↓
Approved External Services

Instead of:
Application Server
↓
Anything
↓
Internet

This is one reason NACLs can be useful as part of a defense-in-depth strategy.
However, overly restrictive egress rules can also break legitimate applications.
Security is therefore a balancing exercise between:
restriction, functionality, and operational complexity.



Security Groups vs NACLs

The two mechanisms should not be treated as competitors.
They solve different problems.
Feature
Security Group
NACL
Scope
Instance/ENI
Subnet
Stateful
Yes
No
Rules
Allow rules
Allow and deny
Return traffic
Automatically tracked
Must be explicitly handled
Primary purpose
Workload protection
Subnet boundary
Best use
Application/host access control
Network segmentation
A useful mental model is:
NACL
↓
"Can this traffic cross the subnet boundary?"

Security Group
↓
"Should this workload accept this traffic?"

Neither should be considered the entire security architecture.



Separating Routing From Firewalling

At this point, the architecture naturally separates into two systems.

Routing

Routing establishes the possible path:
VPC
↓
Subnet
↓
Route Table
↓
Gateway
↓
Destination


Filtering

Filtering determines whether traffic is permitted:
Packet
↓
NACL
↓
Security Group
↓
Workload

This distinction prevents a common design mistake:
Assuming that a valid route automatically means the traffic should be trusted.
It doesn't.
A packet can have a perfectly valid route and still be rejected by the security controls.



The Perimeter Becomes Infrastructure

Once the default VPC abstraction is removed, networking becomes a first-class part of the infrastructure.
The environment now needs to manage:
  • CIDR allocation
  • Subnet boundaries
  • Route tables
  • Internet Gateways
  • NAT Gateways
  • NACLs
  • Security Groups
  • VPC Flow Logs
  • Availability Zones
  • IAM permissions
  • Infrastructure-as-Code state
This creates another security concern:
Who is allowed to change the network?
A developer changing application code is one thing.
An administrator changing a route table is something else entirely.
A malicious or accidental route modification can completely change the security posture of the environment.
That is why network infrastructure should ideally be managed through Infrastructure as Code and monitored for configuration drift.



Infrastructure as Code

There are several ways to implement the architecture.
Two common options are:

Terraform

Terraform provides a declarative Infrastructure-as-Code approach and is widely used for cloud infrastructure.

AWS CDK

AWS CDK allows infrastructure to be defined using familiar programming languages and provides a more programmatic development model.
The tool matters.
But the architecture matters more.
The responsibilities should remain clear:
Route Tables
↓
Traffic direction

NACLs
↓
Subnet-level stateless filtering

Security Groups
↓
Stateful workload protection

IaC
↓
Repeatable infrastructure deployment

The goal should not be to build custom security mechanisms simply because AWS-native controls appear inconvenient.
Security is generally not the best place to reinvent mature infrastructure primitives.



Making the Boundary Visible

A good cloud architecture should make important security decisions visible.
For example:
┌──────────────────────────────────────────────┐
│ VPC: 10.0.0.0/16 │
│ │
│ ┌──────────────────────────────────────────┐ │
│ │ PRIVATE SUBNET: 10.0.2.0/24 │ │
│ │ │ │
│ │ Route Table │ │
│ │ 10.0.0.0/16 → local │ │
│ │ 0.0.0.0/0 → NAT Gateway │ │
│ │ │ │
│ │ NACL │ │
│ │ Default Deny │ │
│ │ Explicit Allow Rules │ │
│ │ │ │
│ │ Security Group │ │
│ │ Application-specific rules │ │
│ │ │ │
│ │ Backend Instance │ │
│ └──────────────────────────────────────────┘ │
└──────────────────────────────────────────────┘

The interface does not need to reproduce the AWS console.
Instead, it should answer the questions that actually matter:
  • Is this subnet public or private?
  • Where does its default route point?
  • Does it use a NAT Gateway?
  • What does the NACL allow?
  • Which Security Group is attached?
  • What traffic is expected?
  • What happens to unexpected traffic?
Visibility itself becomes a security feature.



What the MVP Should Actually Solve

There is always a temptation to build everything immediately:
  • Transit Gateways
  • IPv6
  • Cross-region VPC peering
  • Complex multi-AZ architectures
  • Micro-segmentation
  • Advanced traffic inspection
  • Multiple routing domains
That can quickly turn a focused infrastructure project into an unfinished one.
A better first version should prove the fundamental network path.

MVP Architecture

VPC CIDR Definition
↓
Public/Private Subnet Allocation
↓
Internet Gateway
↓
Public Route Table
↓
NAT Gateway
↓
Private Route Table
↓
Baseline NACLs
↓
Security Groups
↓
EC2 Workloads

Once this works reliably, additional capabilities can be added incrementally.



A Practical Secure Architecture

Putting everything together:
INTERNET
│
▼
┌────────────────┐
│ Internet GW │
└───────┬────────┘
│
┌─────────┴─────────┐
│ │
▼ ▼
PUBLIC SUBNET PRIVATE SUBNET
10.0.1.0/24 10.0.2.0/24
│ │
│ NACL / SG
│ │
Load Balancer Application
│
▼
Database Tier

Traffic flows are intentionally different.
External users can reach the public-facing endpoint.
The application tier remains private.
The database tier is even more restricted.
Outbound traffic from private workloads can use NAT when required.
The network therefore becomes a series of controlled boundaries instead of one flat environment.



The Bigger DevSecOps Lesson

The most important lesson from this architecture is not simply how to configure a VPC.
It is how to think about security.
Security should not be added after infrastructure has already been deployed.
Instead:
Design
↓
Network Boundary
↓
Routing
↓
Access Controls
↓
Infrastructure as Code
↓
Deployment
↓
Monitoring
↓
Continuous Validation

This is where cloud networking connects directly to DevSecOps.
A secure architecture should be:
  • Repeatable through IaC
  • Auditable through logs and configuration history
  • Least-privileged through restricted access
  • Segmented through subnets
  • Observable through network monitoring
  • Resilient through multi-AZ design
  • Testable through automated validation
The network should not depend on someone's memory of how the AWS console was configured six months ago.



The Real Value of Removing the Default

The argument is not that default VPCs are inherently bad.
They solve real problems.
They make AWS easier to learn, simplify deployments, and allow developers to get workloads running quickly.
The value of a custom VPC is different.
It gives you ownership of the boundary.
Instead of accepting the network as a predefined environment, you explicitly define:
VPC
↓
SUBNET
↓
ROUTE
↓
NACL
↓
SECURITY GROUP
↓
WORKLOAD

Every layer has a responsibility.
Every traffic path has a reason.
Every exposed service becomes a deliberate decision.
And every restriction becomes part of the architecture rather than an afterthought.



Conclusion

Cloud networking becomes much more interesting when the default abstraction disappears.
A VPC is not simply a place where EC2 instances live.
It is a system of boundaries, routes, gateways, and security controls.
Subnets determine isolation.
Route tables determine possible paths.
NACLs provide stateless subnet-level filtering.
Security Groups provide stateful workload-level protection.
NAT Gateways provide controlled outbound connectivity.
Infrastructure as Code makes these decisions repeatable.
The key principle is simple:
A packet being able to reach a destination does not mean it should be allowed to reach it.
Secure cloud architecture comes from deliberately separating those two questions.
Where can traffic go?
and
Should that traffic be allowed?
Once those questions become explicit, the VPC stops being a collection of AWS configuration options and becomes what it should be:
a security boundary designed around isolation, controlled traffic flow, and reduced blast radius.



Key Takeaways

  1. Design the network boundary before deploying workloads.
  1. Use public and private subnets according to exposure requirements.
  1. Treat route tables as traffic-direction mechanisms, not firewalls.
  1. Use NACLs for subnet-level stateless filtering where appropriate.
  1. Use Security Groups for stateful workload-level access control.
  1. Use NAT Gateways to provide controlled outbound access to private workloads.
  1. Remember that routing and authorization are different problems.
  1. Design for return traffic when using stateless controls.
  1. Use segmentation to reduce lateral movement and blast radius.
  1. Manage network infrastructure through Infrastructure as Code whenever practical.
  1. Build observability and drift detection into the architecture.
  1. Start with a small, understandable MVP before adding advanced networking features.
The strongest cloud boundaries are not the ones that hide complexity. They are the ones that make the important security decisions explicit.
#buildatpce
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