AWS VPC Architecture Interview Masterclass: Subnets, NAT Gateways, Route Tables, and NACLs vs. Security Groups
· Sourabh G Kulkarni
Prepare for senior AWS DevOps and Cloud Engineer interviews. Master VPC networking: Public vs Private subnets, Route Tables, Internet and NAT Gateways, and the vital differences between Security Groups and NACLs.

AWS VPC Architecture and Subnet Routing
Figure 1: Core AWS VPC topology: traffic routing across Internet Gateways, NAT Gateways, Public and Private Subnets, and dual-layer firewall enforcement.
In almost every AWS Cloud Architect, DevOps, or SRE interview, the networking round starts with one foundational topic: Amazon VPC (Virtual Private Cloud).
Interviewers do not want definitions copied from AWS whitepapers. They test whether you can design production networks from scratch:
"How does a private subnet workload communicate with external APIs securely? Why not just put everything in public subnets? What is the exact packet evaluation order between NACLs and Security Groups?"
If you stumble on subnet math, gateway placement, or firewall statefulness, the interview ends early.
Here is an interview-ready architectural masterclass on AWS VPC networking.
1. The Real Production Topology: Public vs. Private Subnets
A common interview trap is: "What technically makes a subnet 'public' versus 'private'?"
Many candidates say: "A public subnet has public IP addresses." That is wrong.
In AWS, what makes a subnet public or private is its Route Table association:
- Public Subnet: Its associated Route Table has a route targeting an Internet Gateway (
igw-xxxx) for destination0.0.0.0/0. - Private Subnet: Its Route Table does NOT point to an IGW. To reach the internet, it points to a NAT Gateway (
nat-xxxx) or an egress-only internet gateway.
+-----------------------------------------------------------------------------------+
| AWS REGION (e.g. us-east-1) |
| |
| +-----------------------------------------------------------------------------+ |
| | VPC (CIDR: 10.0.0.0/16) | |
| | | |
| | Internet Gateway (igw-0a1b2c) <==================> [Public Internet] | |
| | ^ | |
| | | | |
| | +-----------|---------------------------------------------------------+ | |
| | | PUBLIC SUBNET (10.0.1.0/24) | | |
| | | Route Table: 0.0.0.0/0 -> igw-0a1b2c | | |
| | | | | |
| | | [Application Load Balancer] [NAT Gateway (Elastic IP)] | | |
| | +---------------------------------------------------|-----------------+ | |
| | ^ | |
| | | (Outbound only) | |
| | +---------------------------------------------------|-----------------+ | |
| | | PRIVATE APP SUBNET (10.0.2.0/24) | | | |
| | | Route Table: 0.0.0.0/0 -> nat-09f12a -------------+ | | |
| | | | | |
| | | [EKS Worker Nodes / EC2 Backend Services] | | |
| | +---------------------------------------------------------------------+ | |
| | | |
| | +---------------------------------------------------------------------+ | |
| | | PRIVATE DATABASE SUBNET (10.0.3.0/24 - ISOLATED) | | |
| | | Route Table: Local only (10.0.0.0/16 -> local) - NO INTERNET ACCESS!| | |
| | | | | |
| | | [Amazon RDS PostgreSQL Multi-AZ Cluster] | | |
| | +---------------------------------------------------------------------+ | |
| +-----------------------------------------------------------------------------+ |
+-----------------------------------------------------------------------------------+
2. Interview Question: "Why Must a NAT Gateway Live in a Public Subnet?"
This is a classic senior interview trap.
If a NAT Gateway exists so private EC2 instances can download packages from the internet, why can't the NAT Gateway be deployed in the private subnet alongside them?
The Answer:
- A NAT Gateway must translate private IPs to a public IP using an attached Elastic IP (EIP).
- For outbound packets from that Elastic IP to actually traverse AWS edge routers to the public internet, the gateway's subnet must have a direct route
0.0.0.0/0 -> igw-xxxx. - If you place a NAT Gateway in a private subnet that lacks an IGW route, the NAT Gateway itself has no exit path to the outside world, rendering it completely useless!
3. Security Groups vs. Network ACLs (NACLs): The Core Interview Battleground
Interviewers love asking candidates to compare Security Groups and NACLs. Memorize this comparison matrix:
| Feature / Dimension | Security Group (SG) | Network ACL (NACL) |
|---|---|---|
| Operating Layer | Instance / Elastic Network Interface (ENI) | Subnet boundary |
| Statefulness | Stateful: If inbound traffic is allowed, response outbound traffic is automatically allowed. | Stateless: Return traffic must be explicitly allowed in Outbound rules. |
| Rule Types | ALLOW rules only (Everything else is implicitly denied). | ALLOW and DENY rules evaluated numerically in order. |
| Rule Evaluation | All rules evaluated simultaneously before decision. | Processed in strict sequential order from lowest number to highest (e.g., 100, 200, *). |
| Best Used For | Microservice security (e.g. allowing App SG to talk to DB SG on 5432). | Subnet-wide defense (e.g. blocking known malicious IP CIDRs). |
The Ephemeral Port Gotcha with NACLs:
If an interviewer asks: "I created a custom NACL allowing Inbound port 80/443, but our EC2 instances cannot download updates from apt-get or curl external websites. Why?"
The Answer: NACLs are stateless. When your EC2 instance connects to an external website on port 443, the remote server responds on a temporary ephemeral port (Linux: ports 32768–60999 or IANA 49152–65535). Unless your NACL has an Outbound ALLOW rule for ephemeral ports, the returning packets will be dropped at the subnet boundary!
4. Terraform Architecture Blueprint: Production VPC
Here is the exact battle-tested HCL pattern you should describe during technical design rounds:
# 1. Main VPC
resource "aws_vpc" "production" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
enable_dns_support = true
tags = { Name = "prod-vpc" }
}
# 2. Public Subnet for ALB and NAT Gateway
resource "aws_subnet" "public_1a" {
vpc_id = aws_vpc.production.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
map_public_ip_on_launch = true
tags = { Name = "prod-public-us-east-1a" }
}
# 3. Internet Gateway
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.production.id
}
# 4. Elastic IP & NAT Gateway
resource "aws_eip" "nat" {
domain = "vpc"
}
resource "aws_nat_gateway" "nat" {
allocation_id = aws_eip.nat.id
subnet_id = aws_subnet.public_1a.id # Must be in public subnet!
}
# 5. Private Route Table pointing to NAT
resource "aws_route_table" "private" {
vpc_id = aws_vpc.production.id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.nat.id
}
}
Related Topics to Read Next
- AWS IAM Deep Dive: Roles, Policies, and Cross-Account Access — Mastering cloud identity, permission boundaries, and AssumeRole.
- AWS VPC Peering vs. Transit Gateway vs. PrivateLink — Connecting multiple AWS VPCs and on-premise networks.
- Terraform Remote Backends and State Locking — Automating production cloud infrastructure safely.
- Kubernetes CNI Pod-to-Pod Networking Explained — How AWS VPC CNI assigns native VPC IPs directly to EKS pods.