Skip to main content
Career Paths
Concepts
Vpc Fundamentals
The Simplified Tech

Role-based learning paths to help you master cloud engineering with clarity and confidence.

Product

  • Career Paths
  • Interview Prep
  • Scenarios
  • AI Features
  • Cloud Comparison
  • Resume Builder
  • Pricing

Community

  • Join Discord

Account

  • Dashboard
  • Credits
  • Updates
  • Sign in
  • Sign up
  • Contact Support

Stay updated

Get the latest learning tips and updates. No spam, ever.

Terms of ServicePrivacy Policy

© 2026 TheSimplifiedTech. All rights reserved.

BackBack
Interactive Explainer

VPC Fundamentals: Subnets, Route Tables & Gateways

How a Virtual Private Cloud isolates and routes traffic — covering public vs private subnets, internet gateways, NAT gateways, CIDR blocks, security groups, and network ACLs, with the exact rules that determine what traffic can flow where.

🎯Key Takeaways
A subnet is public if and only if its route table has a 0.0.0.0/0 route pointing to an Internet Gateway
Security groups are stateful (return traffic auto-allowed); NACLs are stateless (must allow both directions explicitly)
Use security group chaining (reference SG IDs) instead of CIDR rules for database access control
NAT Gateways let private resources initiate outbound internet connections — inbound connections are impossible
Use VPC endpoints for S3 and DynamoDB to avoid NAT Gateway data charges for AWS-internal traffic

VPC Fundamentals: Subnets, Route Tables & Gateways

How a Virtual Private Cloud isolates and routes traffic — covering public vs private subnets, internet gateways, NAT gateways, CIDR blocks, security groups, and network ACLs, with the exact rules that determine what traffic can flow where.

~13 min read
Be the first to complete!
What you'll learn
  • A subnet is public if and only if its route table has a 0.0.0.0/0 route pointing to an Internet Gateway
  • Security groups are stateful (return traffic auto-allowed); NACLs are stateless (must allow both directions explicitly)
  • Use security group chaining (reference SG IDs) instead of CIDR rules for database access control
  • NAT Gateways let private resources initiate outbound internet connections — inbound connections are impossible
  • Use VPC endpoints for S3 and DynamoDB to avoid NAT Gateway data charges for AWS-internal traffic

Lesson outline

What is a VPC and Why Does It Exist?

A Virtual Private Cloud (VPC) is a logically isolated section of a cloud provider's network where you launch resources. Without a VPC, every EC2 instance, database, and container would sit on a flat shared network reachable by anyone. The VPC gives you a private address space (CIDR block), network segmentation via subnets, and control over ingress and egress traffic.

Think of a VPC as a private office building. The building has one address on the street (your CIDR block), multiple floors (subnets), a front door that faces the street (internet gateway), a secure internal mail room for outbound packages (NAT gateway), ID badge readers on each room (security groups), and floor-level security checkpoints (network ACLs).

CIDR notation crash course

10.0.0.0/16 means the first 16 bits are fixed, giving you 65,536 addresses (10.0.0.0 to 10.0.255.255). A /24 subnet has 256 addresses. AWS reserves 5 addresses in every subnet (first 4 + last 1), so a /24 gives you 251 usable IPs. For a production VPC, start with a /16 to avoid address exhaustion as you add subnets and services.

ComponentWhat it doesAnalogy
VPCPrivate address space for all your resourcesThe entire office building
SubnetSegment of the VPC CIDR in a single AZA floor of the building
Internet GatewayAllows bidirectional public internet trafficThe front door facing the street
NAT GatewayAllows private resources to reach internet (outbound only)The internal mail room — sends packages out, never lets strangers in
Route TableTells each subnet where to send trafficThe building's internal directory and exit signs
Security GroupStateful firewall at the resource level (EC2, RDS)ID badge reader on each office door
Network ACLStateless firewall at the subnet levelSecurity checkpoint at each floor entrance

Public vs Private Subnets

The most important design decision in a VPC is which subnets are public (internet-reachable) and which are private (internal-only). This single decision determines what your architecture's attack surface looks like.

Public subnet characteristics

  • Route table has a 0.0.0.0/0 → Internet Gateway route — This is the ONLY thing that makes a subnet public. Without this route, even resources with public IPs cannot reach or be reached from the internet.
  • Resources can optionally have public IPs — An EC2 instance in a public subnet still needs a public IP (Elastic IP or auto-assigned) to be reachable from the internet. Subnet type + public IP + security group rule = all three required for internet access.
  • Appropriate for: load balancers, bastion hosts, NAT gateways — Everything that must accept inbound internet traffic lives here. Nothing else should.

Private subnet characteristics

  • Route table has 0.0.0.0/0 → NAT Gateway (for outbound internet) — Private resources can initiate outbound internet connections (to download packages, call external APIs) through the NAT gateway, but no inbound connections are possible from the internet.
  • No public IPs — Resources in private subnets have only private RFC-1918 IP addresses. Even if you assign a public IP by accident, without the internet gateway route, it will not be routable.
  • Appropriate for: application servers, databases, caches, internal queues — Everything that should never be directly accessible from the internet. 90% of your resources should be here.

The three-tier subnet pattern

A production VPC should have at minimum three subnet tiers per AZ: (1) Public subnets for load balancers and NAT gateways, (2) Application subnets (private) for ECS tasks, Lambda, EC2 app servers, (3) Data subnets (private, no NAT route) for RDS, ElastiCache, OpenSearch. Data subnets should not even have internet access via NAT — they only need VPC-internal routes. This limits blast radius if an app server is compromised.

NAT Gateway costs add up fast

AWS NAT Gateway costs $0.045/hour per gateway (~$32/month) plus $0.045 per GB of data processed. A single NAT Gateway processing 1 TB/month adds $45 to your bill — every month. In a multi-AZ setup with one NAT Gateway per AZ (recommended for resilience), that is $96/month before data charges. Use VPC endpoints for S3 and DynamoDB to avoid NAT charges for traffic that never needs to leave AWS.

inspect-vpc.sh
1# Inspect a subnet's route table to determine if it is public or private
The route table destination 0.0.0.0/0 pointing to an IGW is what defines a public subnet
2 aws ec2 describe-route-tables \
3 --filters "Name=association.subnet-id,Values=subnet-0abc123" \
4 --query 'RouteTables[].Routes[].{Dest:DestinationCidrBlock,Target:GatewayId}' \
5 --output table
6
7 # A public subnet shows: 0.0.0.0/0 -> igw-xxxxxxxxx
8 # A private subnet shows: 0.0.0.0/0 -> nat-xxxxxxxxx (or nothing)
9
VPC endpoints for S3 and DynamoDB bypass the NAT Gateway — significant cost saving
10 # List all VPC endpoints (avoid paying NAT fees for S3/DynamoDB)
11 aws ec2 describe-vpc-endpoints \
12 --filters "Name=vpc-id,Values=vpc-0abc123" \
13 --query 'VpcEndpoints[].{Service:ServiceName,Type:VpcEndpointType,State:State}'

Security Groups vs Network ACLs

AWS gives you two layers of network security: security groups (resource-level, stateful) and network ACLs (subnet-level, stateless). Most engineers understand security groups but misunderstand NACLs, which causes subtle connectivity bugs.

FeatureSecurity GroupNetwork ACL
Applies toIndividual resources (EC2, RDS, Lambda ENI)Entire subnet (all resources in it)
StatefulnessStateful — return traffic automatically allowedStateless — must explicitly allow both inbound AND outbound
Rule evaluationAll rules evaluated; most permissive winsRules evaluated in order by number; first match wins
Default (new resource)Deny all inbound, allow all outboundAllow all inbound and outbound (default NACL)
Use casePrimary access control for all resourcesAdditional layer of defence; subnet-level blocking

The stateless NACL trap

If you add a NACL rule to allow inbound TCP port 443 but forget to add the outbound rule for ephemeral ports (1024–65535), all HTTPS requests will silently hang. The SYN packet arrives (inbound 443 allowed), the server responds, but the response packet on an ephemeral port is blocked by the outbound NACL. Security groups do not have this problem because they are stateful. NACLs are most useful for blocking specific IP ranges at the subnet level, not for fine-grained port control.

Security group chaining is more secure than IP-based rules

Instead of allowing inbound port 5432 from 10.0.1.0/24 (a subnet CIDR), allow inbound port 5432 from the security group ID of your application servers (sg-0abc123). This means only resources in that specific security group can connect — not any IP in the subnet. If an attacker compromises a different resource on the same subnet, it still cannot reach your database.

Route Tables and Traffic Flow

Route tables are the nervous system of a VPC. Every subnet is associated with exactly one route table. When a packet leaves a resource, the VPC router looks up the destination IP in the route table and forwards it to the most specific matching route target.

How a packet travels from an app server to the internet

→

01

App server (in private subnet 10.0.2.0/24) initiates a connection to 151.101.1.140 (GitHub).

→

02

VPC router checks the route table for subnet 10.0.2.0/24. Finds: 10.0.0.0/16 → local; 0.0.0.0/0 → nat-0xyz.

→

03

Packet is forwarded to the NAT Gateway in the public subnet.

→

04

NAT Gateway replaces the source IP (10.0.2.45) with its own public Elastic IP and forwards the packet to the Internet Gateway.

→

05

Internet Gateway routes the packet to the public internet.

06

Return traffic comes back to the NAT Gateway's Elastic IP; NAT Gateway translates it back to 10.0.2.45 and delivers it to the app server.

1

App server (in private subnet 10.0.2.0/24) initiates a connection to 151.101.1.140 (GitHub).

2

VPC router checks the route table for subnet 10.0.2.0/24. Finds: 10.0.0.0/16 → local; 0.0.0.0/0 → nat-0xyz.

3

Packet is forwarded to the NAT Gateway in the public subnet.

4

NAT Gateway replaces the source IP (10.0.2.45) with its own public Elastic IP and forwards the packet to the Internet Gateway.

5

Internet Gateway routes the packet to the public internet.

6

Return traffic comes back to the NAT Gateway's Elastic IP; NAT Gateway translates it back to 10.0.2.45 and delivers it to the app server.

The VPC local route always wins

Every VPC route table has an implicit local route (e.g. 10.0.0.0/16 → local) that cannot be deleted or overridden. Traffic between resources in the same VPC always uses this local route, regardless of security group rules. Security groups control whether the traffic is accepted, but routing within the VPC always works — the firewall is not the router.

How this might come up in interviews

Appears in cloud engineer, DevOps engineer, and solutions architect interviews as both direct questions and embedded in system design problems. "Design a secure VPC for a fintech application" is a common prompt that tests subnet design, security layering, and connectivity patterns.

Common questions:

  • Explain the difference between a public and private subnet in AWS.
  • A developer cannot connect from an EC2 instance in a private subnet to the internet. What could be wrong?
  • What is the difference between a security group and a network ACL?
  • Why would you use a VPC endpoint instead of routing traffic through a NAT Gateway?
  • Describe your VPC design for a three-tier web application with public, application, and data tiers.

Try this question: How many AZs are required? What are the egress traffic volumes (affects NAT cost)? Are there any on-premises connectivity requirements (Direct Connect, VPN)? What compliance frameworks apply (affects subnet isolation requirements)?

Strong answer: Draws the three-tier subnet pattern unprompted. Recommends security group chaining over CIDR-based rules. Mentions AWS Config rules for continuous compliance. Raises VPC endpoint cost optimisation without prompting.

Red flags: Thinks a subnet is "public" just because it's labelled that way. Confuses security groups (stateful, resource-level) with NACLs (stateless, subnet-level). Cannot explain why a NAT Gateway allows outbound but not inbound traffic.

Scenario · E-commerce startup

Step 1 of 3

Debug the broken VPC connection

You are a cloud engineer at a fast-growing e-commerce startup. The team just deployed a new microservice architecture on AWS. The frontend application in a public subnet needs to reach an internal payment service EC2 instance in a private subnet, which in turn needs to reach a PostgreSQL RDS instance. The devs say "nothing can connect to anything." You need to diagnose and fix this systematically.

The frontend app server (in public subnet 10.0.1.0/24) cannot reach the payment service EC2 (in private subnet 10.0.2.0/24, port 8080). You check the payment service security group and see: Inbound: allow port 8080 from 10.0.2.0/24.

What is wrong with this security group rule?

Match VPC component to its correct behaviour

0 / 7 matched

Match each VPC component or concept on the left with its defining characteristic on the right.

Quick check · VPC Fundamentals: Subnets, Route Tables & Gateways

1 / 5

What is the ONLY configuration that makes an AWS subnet "public"?

Key takeaways

  • A subnet is public if and only if its route table has a 0.0.0.0/0 route pointing to an Internet Gateway
  • Security groups are stateful (return traffic auto-allowed); NACLs are stateless (must allow both directions explicitly)
  • Use security group chaining (reference SG IDs) instead of CIDR rules for database access control
  • NAT Gateways let private resources initiate outbound internet connections — inbound connections are impossible
  • Use VPC endpoints for S3 and DynamoDB to avoid NAT Gateway data charges for AWS-internal traffic
Before you move on: can you answer these?

An engineer tells you "the subnet is public so resources in it are reachable from the internet." Is this correct?

Not entirely. A subnet being "public" (route table has 0.0.0.0/0 → IGW) is necessary but not sufficient. The resource also needs a public IP, AND the security group must allow inbound traffic on the relevant port. All three conditions must be true. The security group is the most important control — even a public subnet resource with a public IP is unreachable if the SG has no inbound allow rules.

Why does NACL statelessness cause the "HTTPS works inbound but responses never arrive" bug?

NACLs are stateless: they evaluate every packet independently, both directions. If you allow inbound TCP 443 in a NACL but forget to allow outbound traffic on ephemeral ports (1024–65535), the TCP handshake response packets are blocked on the way out. The client sees a SYN-ACK that never arrives. Security groups do not have this problem — they automatically allow return traffic for established connections.

🧠Mental Model

💡 Analogy

Your VPC is a private office building. The building has one street address (your CIDR block like 10.0.0.0/16). Inside, each floor is a subnet. The front door with a security desk is the Internet Gateway — it faces the street and allows visitors in and out. The internal mail room is the NAT Gateway — it sends packages out to the street on behalf of staff on private floors, but strangers cannot use it to get in. Every office room has an ID badge reader (security group) that checks who is allowed to enter. Each floor has a checkpoint at the stairwell (network ACL) that can block entire categories of visitor before they even reach a room.

⚡ Core Idea

A subnet is public if and only if its route table has a 0.0.0.0/0 route pointing to an Internet Gateway. Security groups are stateful resource-level firewalls. Network ACLs are stateless subnet-level firewalls. These three controls together define what traffic can flow where inside your VPC.

🎯 Why It Matters

VPC misconfiguration is the most common cause of accidental cloud data exposure. A database in a public subnet with a permissive security group rule is reachable from the entire internet. Understanding exactly what makes a subnet public (route table, not just the label "public") and how security groups layer with NACLs is foundational knowledge for any cloud engineer.

Ready to see how this works in the cloud?

Switch to Career Paths for structured paths (e.g. Developer, DevOps) and provider-specific lessons.

View role-based paths

Sign in to track your progress and mark lessons complete.

Discussion

Questions? Discuss in the community or start a thread below.

Join Discord

In-app Q&A

Sign in to start or join a thread.