Volume 2 · Chapter 2 — AWS Networking Deep Dive (VPC)

Routing, Internet and NAT Gateways

Goutham Mayaluri 10 min read AWSCloudVPCNAT GatewayNetworking

2.1 Introduction

If subnets are the rooms of your network, routing is the set of doors and hallways that decides where traffic can go. Route tables, the internet gateway, and the NAT gateway together determine which subnets can reach the internet, in which direction, and how private resources get outbound access without becoming publicly reachable. This is the machinery behind the public/private subnet distinction, and it’s a favourite interview area because it separates people who memorized “public subnet” from those who understand why a subnet is public. This chapter makes the traffic flow concrete.

2.2 Route Tables

A route table is a set of rules that decides where network traffic is directed based on its destination address. Every subnet is associated with exactly one route table, and that association is what actually makes a subnet public or private. A route table always contains a local route that allows all resources within the VPC to communicate with each other; beyond that, you add routes for external destinations. The crucial route is the default route0.0.0.0/0, which means “any address not matched by a more specific route” - effectively “the internet.” Where that default route points determines the subnet’s character: if it points to an internet gateway, the subnet is public; if it points to a NAT gateway, the subnet is private-with-outbound; if there’s no default route at all, the subnet is fully private.

2.3 The Internet Gateway

An internet gateway (IGW) is the component that connects a VPC to the public internet. There is one IGW per VPC, attached at the VPC level, and it enables two-way internet communication for resources that have a public IP address and sit in a subnet whose route table sends0.0.0.0/0to the IGW. So three things must all be true for a resource to be reachable from the internet: it’s in a subnet routed to the IGW (a public subnet), it has a public IP, and security rules permit the traffic. Removing any one of these severs internet reachability - which is why a database with no public IP, in a private subnet, is unreachable from outside even though the VPC has an internet gateway attached.

flowchart LR
  Internet((Internet)) <--> IGW[Internet Gateway]
  IGW <--> LB[Load Balancer - public subnet]
  LB --> App[App server - private subnet]
  App --> NAT[NAT Gateway - public subnet]
  NAT --> IGW
  App -. no inbound path from internet .-x Internet

2.4 The NAT Gateway

A NAT (Network Address Translation) gateway solves a specific problem: resources in private subnets often need outbound internet access - to download OS patches, call an external API, or reach a software repository - but must never be reachable from the internet inbound. A NAT gateway, placed in a public subnet, lets private resources initiate outbound connections while blocking any unsolicited inbound connection. The private subnet’s route table sends0.0.0.0/0to the NAT gateway; the NAT gateway forwards that traffic out through the internet gateway using its own public address, and return traffic flows back the same way - but no one on the internet can start a connection into the private resource. This gives private resources internet access for updates and outbound calls while preserving their unreachability, which is exactly what a bank’s private application tier needs.

2.5 Putting the Flow Together

The complete picture: inbound customer traffic enters through the internet gateway to a load balancer in a public subnet, which forwards it over private networking to application servers in private subnets. When those application servers need to make an outbound call - fetching a patch or calling an external service - their traffic goes to the NAT gateway in the public subnet and out through the internet gateway, returning by the same path. The database, in a private subnet with no default route at all, has neither inbound nor outbound internet access and talks only to the application tier inside the VPC. Every subnet’s role is defined purely by its route table, which is the single most important thing to internalize about AWS networking.

2.6 Banking Production Scenario

A bank’s VPC has an internet gateway attached. Its public subnets (route0.0.0.0/0to the IGW) hold the load balancers and NAT gateways. Its private application subnets route0.0.0.0/0to a NAT gateway, so application servers can download security patches and call approved external payment networks outbound, but nothing on the internet can initiate a connection to them. The database subnets have no default route at all - the database is completely sealed from the internet in both directions and reachable only from the application tier. For resilience, a NAT gateway is deployed in each AZ’s public subnet so an AZ failure doesn’t sever outbound access for the surviving zone. This layered routing is what gives the bank internet-reachable front doors and fully sealed sensitive tiers simultaneously.

2.7 Troubleshooting: Connectivity Failures

Most VPC connectivity incidents trace back to routing. “My instance can’t reach the internet” usually means either it’s in a private subnet with no route to a NAT gateway (add or fix the route), or it’s in a public subnet but lacks a public IP (assign one or use a NAT path), or a security rule is blocking it. “Traffic can’t reach my public instance from outside” usually means the subnet isn’t routed to the internet gateway, the instance has no public IP, or security rules deny the inbound traffic - the three conditions that must all hold. A common single-AZ resilience bug is deploying just one NAT gateway: if it or its AZ fails, every private subnet loses outbound access, so production deploys a NAT gateway per AZ. The diagnostic discipline is to check, in order: the subnet’s route table, the resource’s IP, and the security group and NACL rules.

Interview Question

Explain how a route table, internet gateway, and NAT gateway work together to make subnets public or private.

These three components together define every subnet’s connectivity, and understanding their interaction is the heart of AWS networking. A route table is a set of rules that directs traffic based on its destination address, and every subnet is associated with exactly one route table - that association is literally what makes a subnet public or private. Every route table has a local route letting all resources in the VPC talk to each other; the decisive entry is the default route0.0.0.0/0, meaning “any destination not matched more specifically,” which effectively means the internet, and where it points defines the subnet. An internet gateway is the component attached to the VPC that connects it to the public internet, enabling two-way communication for resources that have a public IP and sit in a subnet whose route table sends0.0.0.0/0to that gateway - that combination is what a public subnet is. So for something to be reachable from the internet, three things must all be true: it’s in a subnet routed to the internet gateway, it has a public IP, and security rules allow the traffic; remove any one and it’s not reachable. A NAT gateway solves the opposite need: private resources frequently must make outbound calls - patch downloads, external APIs - but must never accept inbound connections from the internet. You place a NAT gateway in a public subnet, and the private subnet’s route table sends0.0.0.0/0to the NAT gateway; it forwards that outbound traffic through the internet gateway under its own public address and lets return traffic back, but blocks any unsolicited inbound connection. So the three subnet types fall out of routing: a public subnet routes the default to the internet gateway (two-way, for load balancers and NAT gateways); a private-with-outbound subnet routes the default to a NAT gateway (outbound only, for application servers); and a fully private subnet has no default route at all (no internet either way, for databases). The whole flow becomes: inbound traffic enters via the internet gateway to a load balancer in a public subnet, which forwards to app servers in private subnets, whose outbound calls exit via a NAT gateway back through the internet gateway, while the database sits in a fully private subnet reachable only inside the VPC. The one thing to truly internalize is that a subnet’s public or private nature is entirely a property of its route table - not a checkbox - which is why diagnosing connectivity always starts with the route table.

Interview Question

A resource in a private subnet needs to download patches from the internet but must not be reachable from it. How do you enable this, and how do you make it resilient?

This is exactly what a NAT gateway is for. The requirement has two halves - outbound internet access for the private resource, but no inbound reachability from the internet - and a NAT gateway satisfies both. I place a NAT gateway in a public subnet (one that routes to the internet gateway), and I configure the private subnet’s route table so its default route0.0.0.0/0points to the NAT gateway. Now when the private resource initiates an outbound connection - to download OS patches, reach a package repository, or call an approved external API - the traffic goes to the NAT gateway, which forwards it out through the internet gateway using its own public IP, and the response returns along the same path. Because NAT only permits connections that originate from inside, no one on the internet can initiate a connection to the private resource: it gets outbound access while remaining completely unreachable inbound, which is precisely the security posture a bank’s private application tier requires. To make this resilient, I do not rely on a single NAT gateway, because if it - or the Availability Zone it sits in - fails, every private subnet routed to it loses outbound internet access, which can break patching and external calls across the whole environment. Instead I deploy a NAT gateway in each Availability Zone’s public subnet, and I point each AZ’s private subnets at the NAT gateway in their own AZ. That way an AZ failure only affects that zone, the surviving zones keep their outbound access through their local NAT gateways, and I also avoid cross-AZ data-transfer cost and latency for NAT traffic. So the answer is: NAT gateway in a public subnet, private subnet’s default route pointed to it for outbound-only access, and one NAT gateway per AZ with zone-local routing for resilience. I’d also confirm the security groups and network ACLs allow the outbound traffic, and note that the database tier, which needs no internet at all, gets no default route whatsoever - sealed in both directions - rather than a NAT route it doesn’t need.

Chapter Revision Notes

  • A route table directs traffic by destination; each subnet has exactly one, and it defines public vs private.
  • The default route 0.0.0.0/0 is the deciding entry: to an internet gateway = public; to a NAT gateway = private-outbound; none = fully private.
  • Internet reachability needs all three: subnet routed to the IGW, a public IP, and permissive security rules.
  • A NAT gateway (in a public subnet) gives private resources outbound internet access while blocking all inbound.
  • Deploy a NAT gateway per AZ with zone-local routing for resilience and to avoid cross-AZ cost.