Amazon VPC Design: Subnets, Routing, NAT, Security Groups and NACLs
An Amazon Virtual Private Cloud (VPC) is your own isolated network in an AWS Region. You choose its IP range, split it into subnets, decide what is reachable from the internet and control traffic with routing and firewalls.
Reference design: two tiers in two AZs
flowchart TB
I((Internet)) --- IGW[Internet gateway]
subgraph VPC["VPC 10.0.0.0/16"]
subgraph AZa[AZ a]
PA["Public subnet 10.0.1.0/24<br/>ALB · NAT gateway"]
QA["Private subnet 10.0.11.0/24<br/>app servers"]
DA["DB subnet 10.0.21.0/24<br/>RDS primary"]
end
subgraph AZb[AZ b]
PB["Public subnet 10.0.2.0/24"]
QB["Private subnet 10.0.12.0/24"]
DB["DB subnet 10.0.22.0/24<br/>RDS standby"]
end
end
IGW --- PA & PB
QA -->|0.0.0.0/0| PA
QB -->|0.0.0.0/0| PB
Building blocks
| Component | Role |
|---|---|
| CIDR block | VPC address range, /16 to /28 (e.g. 10.0.0.0/16 = 65,536 addresses) |
| Subnet | A range inside the VPC, in one AZ; AWS reserves 5 addresses per subnet |
| Route table | Rules: destination CIDR → target; every subnet uses exactly one |
| Internet gateway (IGW) | Two-way internet access for public subnets (one per VPC) |
| NAT gateway | Lets private subnets reach the internet outbound only; lives in a public subnet with an Elastic IP |
| Elastic IP | Static public IPv4 address |
A subnet is public only because its route table has 0.0.0.0/0 → igw-…. A private subnet routes 0.0.0.0/0 → nat-… (or nowhere). Instances still need a public IP to be reachable from the internet.
Security groups vs network ACLs
| Security group | Network ACL | |
|---|---|---|
| Applies to | Network interface (instance) | Subnet |
| State | Stateful – return traffic allowed | Stateless – allow both directions explicitly |
| Rules | Allow only | Allow and deny, evaluated in number order |
| Default | Deny all inbound, allow all outbound | Default NACL allows all |
| Typical use | Main firewall; reference other SGs | Extra subnet-level guard, block an IP range |
Connecting VPCs and services
| Need | Solution |
|---|---|
| Reach S3/DynamoDB privately (no NAT cost) | Gateway VPC endpoint |
| Reach other AWS services/SaaS privately | Interface endpoint (PrivateLink) |
| Connect two VPCs | VPC peering (non-transitive) |
| Connect many VPCs and on-premises | Transit Gateway |
| Connect your office | Site-to-Site VPN or Direct Connect |
| See traffic | VPC Flow Logs to CloudWatch/S3 |
CIDR planning tips
- Use a large VPC (/16) with non-overlapping ranges across VPCs and on-premises networks.
- Leave room: one public, one private (app) and one data subnet per AZ.
/24subnets give 251 usable addresses.
Practise it
Virtual lab · Amazon Web Services · 40 min
Build a custom VPC with public and private subnets
Design a two-tier network from scratch: VPC, subnets in two Availability Zones, an internet gateway, a public route table and a web-tier security group – then prove it works by launching an instance into it.
Virtual lab · Amazon Web Services · 35 min
Give a private subnet outbound internet with a NAT gateway
Extend a VPC with a NAT gateway so private instances can download updates while staying unreachable from the internet – a core Solutions Architect pattern.
Quick revision
- VPC → subnets (one AZ each) → route tables.
- Public = route to IGW; private = route to NAT (outbound only).
- NAT gateway sits in a public subnet with an Elastic IP.
- SG = stateful, instance-level, allow only; NACL = stateless, subnet-level, allow/deny.
- Endpoints, peering, Transit Gateway and VPN connect networks privately.
Practise this topic
Hands-on virtual labs
Apply what you just read in a realistic, guided simulation. Free with a verified account.
Create a free account to track your progress and unlock virtual labs.