Route tables, internet gateways and NAT

Beginner · 15 min

What makes a subnet public or private: route selection, internet gateways, public IPv4 addresses, zonal and regional NAT gateways and their costs.

Before thisVPCs, subnets and address planning

Be A Better Dev · 15 min

Route tables, internet gateways and NAT

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Be A Better DevReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Each subnet uses one route table, and the most specific matching route wins. The local route for the VPC is always there.
  • A public subnet has a route to an internet gateway. A resource also needs a public IP address to use it.
  • A NAT gateway lets private resources open connections out without being reachable from the internet.
  • A zonal NAT gateway lives in one zone, so use one per zone with matching route tables. A regional NAT gateway spans zones itself.
  • NAT gateways and public IPv4 addresses are billed by the hour, and NAT also per gigabyte.
  • For IPv6, an egress-only internet gateway gives outbound-only access.

Where should this packet go?

Your VPC has addresses and subnets. A server in it wants to download an update. Something has to decide where that packet goes next, and for anything outside the VPC the answer starts as “nowhere”.

A route table is the list that decides. Each entry says: for this destination range, send to this target. Every subnet is associated with exactly one table, the VPC’s main table if you choose none. When several routes match, the most specific one wins. One entry is always present: the VPC’s own range to local.

The internet gateway

An internet gateway (IGW) is the VPC’s door to the internet. It is managed, redundant, free of hourly charges and not a bandwidth bottleneck. You attach one to the VPC and add a route:

0.0.0.0/0  ->  igw-...

A subnet whose table has that route is what people call public. There is no “public” checkbox.

A route is not enough on its own. The instance also needs a public IPv4 address, either assigned at launch or an Elastic IP that you own and can move. The instance never sees it: its interface holds only the private address, and the gateway translates one to one. Since February 2024 every public IPv4 address is billed, 0.005 USD per hour as of November 2026, whether in use or idle.

NAT: out but not in

Application servers should not be reachable from the internet, but they still need to fetch packages and call outside APIs. Network address translation solves this. A NAT gateway takes connections from private addresses, sends them out from its own public address, and returns the replies. Nobody outside can start a connection inward.

It is like an office switchboard: staff can dial out, and the person called sees only the main number.

Classic (zonal) layout, per zone:

Subnet Route 0.0.0.0/0 to Holds
public internet gateway NAT gateway, load balancer
private the NAT gateway in the same zone applications
data none databases
aws ec2 create-nat-gateway --subnet-id <public-subnet> --allocation-id <eip>
aws ec2 create-route --route-table-id <private-rt> \
    --destination-cidr-block 0.0.0.0/0 --nat-gateway-id nat-...

Built against an emulator, the three tables come out as the theory says:

main        10.20.0.0/16 local
public-a    10.20.0.0/16 local    0.0.0.0/0 igw-92b5...
private-a   10.20.0.0/16 local    0.0.0.0/0 nat-5192...

A zonal NAT gateway is redundant within its zone only. One gateway shared by three zones means one zone’s failure takes outbound access from all of them, and adds cross-zone charges.

Since late 2025 there is also the regional NAT gateway: one gateway ID for the whole VPC that expands and contracts across zones with your workloads. It needs no public subnet of its own, and all private subnets can use the same route. Expansion into a new zone can take up to 60 minutes, during which traffic crosses zones. It is billed per zone per hour, and it does not support private NAT.

What NAT costs, and its limits

In eu-west-1, November 2026 list price, a NAT gateway is 0.048 USD per hour plus 0.048 USD per GB processed. Idle, that is about 35 USD a month each; three zones, about 105 USD before any traffic. Data charges are the part that surprises people: pulling container images or reading S3 through NAT pays per gigabyte. A free gateway endpoint removes the S3 and DynamoDB share.

Two operational limits. Each public address supports up to 55,000 simultaneous connections to one destination address, port and protocol, so add addresses if many clients hammer one endpoint. And idle connections are dropped after 350 seconds, so long quiet connections need TCP keepalives.

IPv6

IPv6 addresses are globally routable, so there is nothing to translate. For outbound-only access use an egress-only internet gateway on the ::/0 route. A NAT gateway can also translate IPv6 clients to IPv4 services (NAT64).

About the video

The embed is Be A Better Dev’s “What is an Internet Gateway?”, March 2021, 15 minutes. Its chapters cover what an internet gateway is, why it matters, its characteristics, an architecture example and private subnet traffic. It predates public IPv4 charges and regional NAT gateways. I judged it from chapters and description, since transcripts couldn’t be fetched. The re:Invent session in deeper has chapters on route tables, internet connectivity, Elastic IPs and NAT.

What was run: the route tables are from moto, a local emulator, which forwards no packets, so connectivity was not tested. Prices are from AWS’s public price data for Ireland. Gateway behaviour and limits are from AWS documentation, all checked in November 2026.

Where this fits

Routes decide where traffic can go. Firewalls decide whether it is let through: security groups and network ACLs.

Check yourself

  1. 01An instance in a subnet with a route to an internet gateway cannot reach the internet. It has only a private address. Why?

    An internet gateway translates between an instance's private address and its public one. Without a public IPv4 address there is nothing to translate to. Use a NAT gateway or give it a public address.

  2. 02A route table has 0.0.0.0/0 to a NAT gateway and 10.50.0.0/16 to a peering connection. Where does traffic for 10.50.1.9 go?

    Over the peering connection, because /16 is more specific than /0.

  3. 03Three zones share one zonal NAT gateway in zone a. What two problems does that cause?

    If zone a fails, the other zones lose outbound access too. And traffic from b and c crosses zones to reach it, which adds data transfer charges.

  4. 04Can someone on the internet open a connection to a server through your NAT gateway?

    No. A NAT gateway only allows connections started from inside, plus their replies. To accept inbound traffic you put a load balancer or similar in a public subnet.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark