Routing Traffic with Route Tables and Gateways
This lesson explains how route tables decide where traffic leaves a subnet, and how internet gateways, NAT gateways and egress-only internet gateways connect subnets to the internet.
Learning outcomes
After completing this lesson, you will be able to:
- Explain route table association and route selection.
- Distinguish internet and egress-only internet gateways.
- Design NAT gateways for each Availability Zone.
Route tables
Each subnet is associated with exactly one route table; subnets without an explicit association use the VPC's main route table. Every route table has a local route for the VPC CIDR that cannot be removed, so all subnets in a VPC can reach each other subject to security groups and NACLs. Further routes send destinations to targets: internet gateway, NAT gateway, VPC peering connection, transit gateway, virtual private gateway, gateway endpoint (as a prefix list), network interface or Gateway Load Balancer endpoint. The most specific route (longest prefix) wins. Gateway route tables associated with an internet gateway or virtual private gateway can redirect incoming traffic through a firewall appliance. Route propagation adds routes learned from a virtual private gateway automatically.
Which route wins?
Internet and egress-only internet gateways
An internet gateway (IGW) is a horizontally scaled, highly available component attached to a VPC that allows communication with the internet. For an instance to be reachable from the internet, its subnet's route table needs 0.0.0.0/0 (or ::/0) to the IGW, the instance needs a public IPv4 address or Elastic IP (the IGW performs one-to-one NAT), and security groups and NACLs must allow the traffic. An egress-only internet gateway is the IPv6 counterpart of NAT: it allows IPv6 instances to initiate outbound connections to the internet and blocks connections initiated from the internet. IPv6 addresses are globally unique, so an IPv6 route to an ordinary IGW would make instances reachable.
Which gateway?
NAT gateways
A NAT gateway lets instances in private subnets initiate outbound IPv4 connections (for updates and AWS APIs) while preventing inbound connections. A zonal public NAT gateway lives in a public subnet of one AZ with an Elastic IP, and private subnets route 0.0.0.0/0 to it; for resilience, create one per AZ and route each AZ's private subnets to their local NAT gateway, which also avoids cross-AZ charges. Since November 2025, a regional NAT gateway spans the VPC's AZs automatically, does not need a public subnet and expands into new AZs as workloads appear, removing per-AZ route management. NAT gateways scale to 100 Gbps, support up to 55,000 simultaneous connections per destination per IP (more with additional IPs), and charge per hour and per GB processed. Private NAT gateways translate between overlapping private networks. Monitor ErrorPortAllocation (port exhaustion), PacketsDropCount and BytesOutToDestination.
| Gateway | Direction | IP version | Placement |
|---|---|---|---|
| Internet gateway | Inbound and outbound | IPv4 (with public IP) and IPv6 | Attached to VPC |
| NAT gateway (zonal) | Outbound only | IPv4 | Public subnet in one AZ, Elastic IP |
| NAT gateway (regional) | Outbound only | IPv4 | VPC-wide across AZs, no public subnet needed |
| Egress-only internet gateway | Outbound only | IPv6 | Attached to VPC |
The following diagram compares a NAT gateway placed in a private subnet with one in a public subnet.

A private subnet that cannot reach the internet
Instances in a private subnet cannot download packages. Their route table sends 0.0.0.0/0 to a NAT gateway, and security groups allow outbound HTTPS. The NAT gateway was created in a private subnet, whose route table has no route to the internet gateway, so it has no path out. Recreating the zonal NAT gateway in a public subnet (or replacing it with a regional NAT gateway) and updating the route fixes the problem. The NACL on the private subnet must also allow return traffic on ephemeral ports.
aws ec2 describe-route-tables --filters Name=association.subnet-id,Values=subnet-0priv \
--query 'RouteTables[].Routes[].[DestinationCidrBlock,NatGatewayId,GatewayId,State]' --output table
aws ec2 describe-nat-gateways --nat-gateway-ids nat-0abc --query 'NatGateways[].[SubnetId,State]'Two routes match a destination. Which is used?
Show answer
The most specific one: the longest prefix wins.
Exam Tips
Remember for the exam
- Each subnet uses one route table; the local route cannot be removed; longest prefix wins.
- Internet access needs an IGW route, a public IP and permissive SGs and NACLs.
- Zonal NAT gateways belong in public subnets; use one per AZ or a regional NAT gateway.
- Egress-only internet gateways give IPv6 outbound-only access.
- ErrorPortAllocation indicates NAT port exhaustion.