How it works
The explanation, with examples you can run.
A common layout
VPC 10.20.0.0/16 (eu-west-1) public-a 10.20.0.0/20 route 0.0.0.0/0 -> internet gateway (load balancers, NAT) public-b 10.20.16.0/20 route 0.0.0.0/0 -> internet gateway private-a 10.20.64.0/19 route 0.0.0.0/0 -> NAT gateway (app tasks, instances) private-b 10.20.96.0/19 route 0.0.0.0/0 -> NAT gateway data-a 10.20.160.0/21 no default route (databases) data-b 10.20.168.0/21 no default routeEvery route table also has a local route for the VPC's own range, so all subnets can reach each other unless security groups or network ACLs say otherwise. "Public" means only that the route table points 0.0.0.0/0 at an internet gateway; an instance there also needs a public IPv4 address (or IPv6) to be reachable. A private subnet has no such route, so nothing on the internet can start a connection to it.
NAT: outbound only, and not free
Instances in private subnets still need to call out: to download packages, pull images or call third-party APIs. A NAT gateway translates their private addresses to its own public one, so replies come back but nobody outside can start a connection. Two things bite:
- Zones. A standard (zonal) NAT gateway lives in one zone. If every private subnet routes through the one in zone a, losing zone a cuts outbound access everywhere, and traffic from the other zones also pays cross-zone transfer. Run one per zone, each with its own route table, or use a regional NAT gateway, which expands across the zones where you have workloads and uses a single ID in all routes.
- Cost. You pay for each hour the gateway exists and for every gigabyte it processes, on top of normal data transfer. A busy service pulling container images or talking to S3 through NAT can cost more in NAT processing than in compute.
Keep AWS traffic off the NAT
VPC endpoints let private subnets reach AWS services without the internet. Gateway endpoints (only S3 and DynamoDB) are entries in your route tables and have no charge. Interface endpoints (PrivateLink) put a network interface for a service such as ECR, SQS or Secrets Manager in your subnets; they are billed per hour and per gigabyte, but often still cost less than NAT for heavy traffic and keep that traffic inside AWS.
Plan addresses once
You cannot easily renumber a VPC later, and peering or Transit Gateway connections fail when ranges overlap. Pick non-overlapping ranges per VPC and environment from the start, leave room for more zones and subnets, and remember that AWS reserves five addresses in every subnet.
Check yourself
3 questions. Get them all right to finish this topic.
0 of 3 right so far. Get all three to finish this topic.