Route Tables and Gateways
Routing rules and the gateways that execute them
Route tables decide which direction packets flow; gateways decide where they leave. Internet Gateways, NAT, VPN, Transit Gateway and endpoints each serve a distinct purpose.
What you will learn
- Read and design route tables
- Choose the right gateway per job
- Understand egress protection (NAT) and private connectivity (endpoints)
Route tables are destination→next-hop lists; gateways are the next hops. Internet Gateway opens a public path, NAT gives one-way egress, Transit Gateway stitches many VPCs, and VPC endpoints reach cloud services without leaving the network.
What is this?
Each subnet has a route table: longest-prefix matching picks the entry (local VPC CIDR internally; 0.0.0.0/0 to a gateway). Gateways: Internet Gateway (AWS) / public gateway (Azure) give inbound+outbound; NAT gateway gives outbound-only; VPN gateway/Cloud VPN and Transit Gateway/VNet hub route hybrid and multi-VPC traffic; VPC endpoints/PrivateLink reach cloud services privately.
Why do you need it?
- Route tables execute your architecture — get the default route wrong and nothing works.
- NAT vs IGW decides whether a private workload ever gets inbound exposure.
- Transit Gateway vs direct peering trades scale and complexity at the network layer.
- Endpoints keep high-volume traffic off public paths and cut egress.
Mental model
A road map and its bridges
Route tables and gateways
Destination signs (route tables) send cars down streets; bridges (gateways) cross rivers. An Internet Gateway is the highway junction everywhere; NAT is a one-way toll bridge; the Transit Gateway is the central interchange connecting districts.
How it works
- Route table: each entry is 'destination CIDR → target (local/IGW/NAT/peering/endpoint)'.
- Longest-prefix match decides which entry wins when ranges overlap.
- Internet Gateway is a plain path for public-facing resources; route 0.0.0.0/0 to it.
- NAT gateway sits in a public subnet, sources outbound traffic, and refuses unsolicited inbound.
- Transit Gateway centralizes VPC peering and VPN attachments in one hub.
- VPC endpoints reach cloud APIs via private IPs (gateway-type for S3/DynamoDB).
Route table to gateway flow.
In production
- Public ALB subnets route via IGW; app subnets egress via NAT; DB subnets have no default route at all.
- A multi-account org attaches 40 VPCs to a Transit Gateway for shared inspection.
- A data platform adds an S3 gateway endpoint to cut NAT traffic and egress.
Best practices
- Think 'least egress': only the routes needed, to the minimal target.
- Keep one NAT gateway per AZ with a route on each subnet (NAT is AZ-scoped).
- Name routes and gateways by function; a dangling default route is invisible until an outage.
- Use endpoints for high-volume S3/DynamoDB access.
Common mistakes
- Routing private subnets to IGW 'so they have internet' — they now have inbound too.
- Single NAT gateway in one AZ = region-wide dependency on one point.
- Forgetting the local route when peering.
- Egress via NAT for services that have endpoints — cost and latency both worse.
Common issues
Instance has a public IP but can't be reachedRoute table sends 0.0.0.0/0 to NAT instead of IGW, or a security layer blocks
Point the public subnet's default route at the Internet Gateway and verify SG/NSG.
NAT gateway cost spikesHigh egress volumes routed through NAT when endpoints exist
Add gateway/interface endpoints and route that traffic privately.
Cross-VPC traffic black-holesPeering route missing on one or both route tables
Add destination peer-CIDR → peering next-hop in every involved route table.
Debugging tips
- Reachability analyzer / IP flow verify names the blocking route or rule.
- Check the subnet's ASSOCIATED route table, not the VPC's main one.
- A public IP with a private-only route = no internet, whichever way you spin it.
- Beware endpoint scope: gateway endpoints only work from subnets with an associated endpoint route.
Interview checkpoint
Quick quiz
Which gateway gives private instances one-way internet egress?
A gateway-type VPC endpoint for S3 is free and keeps traffic off the public internet.