Lesson 2 of 3 Amazon VPC Configuration

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.

Scenario questions

Which route wins?

Exam skills 5.1.1 · 5.3.1

Work out which route a packet follows.

Log in to try this activity Interactive activities are free with an account.

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.

Sort into groups

Which gateway?

Exam skills 5.1.1

Choose the gateway each requirement needs.

Log in to try this activity Interactive activities are free with an account.

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.

GatewayDirectionIP versionPlacement
Internet gatewayInbound and outboundIPv4 (with public IP) and IPv6Attached to VPC
NAT gateway (zonal)Outbound onlyIPv4Public subnet in one AZ, Elastic IP
NAT gateway (regional)Outbound onlyIPv4VPC-wide across AZs, no public subnet needed
Egress-only internet gatewayOutbound onlyIPv6Attached to VPC

The following diagram compares a NAT gateway placed in a private subnet with one in a public subnet.

Where a zonal NAT gateway must be placed. A private route table sends 0.0.0.0/0 to the NAT gateway, but if the NAT gateway itself is in a private subnet with no route to the internet gateway, it has no path out. A NAT gateway in a public subnet, or a Regional NAT gateway, completes the path.
A NAT gateway's own subnet needs a default route to the internet gateway.
Worked example

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]'
Check yourself

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.