SkillSprout
Chapter 4 · Lesson 5
Intermediate
8 min read

NAT Gateway

Overview

A NAT Gateway is a managed AWS service that lets resources in a private subnet start outbound connections to the internet (for patches, package downloads, third-party APIs) while preventing the internet from starting connections back to them. It translates the private source IP to its own public address, then translates replies back.

The NAT Gateway itself lives in a public subnet and uses an Elastic IP. Private subnets send 0.0.0.0/0 to it through their route table, and the NAT Gateway forwards the traffic through the Internet Gateway.

It replaced the older self-managed NAT instance. A NAT Gateway scales automatically up to 100 Gbps, needs no patching and is highly available within its AZ. To survive an AZ failure you deploy one NAT Gateway per AZ — a design that appears constantly on the exam.

Key Concepts

  • A NAT Gateway is AZ-scoped (zonal): it is redundant inside its AZ, but an AZ outage takes it down.
  • For public NAT it must sit in a public subnet with an Elastic IP; private subnets route 0.0.0.0/0 -> nat-xxxx.
  • Bandwidth starts at 5 Gbps and scales automatically to 100 Gbps; it supports up to 55,000 simultaneous connections per destination.
  • It is outbound-only: unsolicited inbound connections from the internet are dropped.
  • Pricing = hourly charge + per-GB data processing (plus standard data transfer out); the cost can become large.
  • Private NAT Gateways (no EIP) route traffic between VPCs/on-premises over Transit Gateway or VGW to hide overlapping CIDRs.
  • NAT Gateways do not use security groups; control access with the source instance's SG and subnet NACLs.
  • A NAT instance is a self-managed EC2 alternative: cheaper at very low traffic but you manage HA, patching and sizing, and must disable source/destination check.
  • For AWS services use VPC endpoints to avoid NAT data-processing charges.

Detailed Notes

How traffic flows

  1. A private instance sends a packet to a public address; its subnet route table sends 0.0.0.0/0 to the NAT Gateway.
  2. The NAT Gateway replaces the source IP with its Elastic IP and keeps a connection-tracking entry.
  3. The packet leaves through the Internet Gateway.
  4. The reply returns to the Elastic IP; the NAT Gateway maps it back to the instance.
bash
# Allocate an Elastic IP and create the NAT Gateway in a PUBLIC subnet
EIP=$(aws ec2 allocate-address --domain vpc --query AllocationId --output text)
NAT=$(aws ec2 create-nat-gateway --subnet-id subnet-pub-a --allocation-id $EIP \
      --query NatGateway.NatGatewayId --output text)
aws ec2 wait nat-gateway-available --nat-gateway-ids $NAT

# Point the private subnet's route table at it
aws ec2 create-route --route-table-id rtb-private-a --destination-cidr-block 0.0.0.0/0 --nat-gateway-id $NAT

Zonal design and high availability

A NAT Gateway is created in one subnet in one AZ. AWS makes it redundant inside that AZ, but if the AZ fails the NAT Gateway is gone. The recommended pattern:

  • One NAT Gateway per AZ, in that AZ's public subnet.
  • One private route table per AZ, each pointing at its own AZ's NAT Gateway.

This avoids a single point of failure and cross-AZ data transfer charges (about $0.01/GB each way). A cheaper dev/test design uses a single NAT Gateway, accepting the AZ-failure risk.

NAT Gateway vs. NAT instance

FeatureNAT GatewayNAT instance
ManagementFully managedYou patch/maintain the AMI
AvailabilityHA within AZ; one per AZ for multi-AZYou script failover (ASG, scripts)
Bandwidth5 Gbps -> 100 Gbps autoDepends on instance type
Security groupsNot supportedSupported
Port forwarding / bastionNoYes
Source/dest checkn/aMust be disabled
Public IPElastic IP required (public NAT)EIP or public IP
CostHourly + per GB processedInstance cost only
Typical choiceProduction defaultTiny, cost-sensitive or special needs

Public vs. private NAT Gateway

TypeEIPSubnetUse
Public (default)RequiredPublicOutbound internet access
PrivateNoneAnyTranslate to a routable private IP for overlapping-CIDR connectivity over TGW/VGW

Private NAT Gateways cannot reach the internet even if routed to an IGW.

Pricing and limits

  • Approximately $0.045 per hour (US East) plus $0.045 per GB processed; both apply even if traffic is intra-Region.
  • Supports TCP, UDP and ICMP, and up to 55,000 simultaneous connections per unique destination (more by adding EIPs / secondary IPs).
  • Allocated with one EIP by default; you can associate extra IPs to scale ports.
  • IPv6: a NAT Gateway supports DNS64/NAT64 so IPv6-only workloads can reach IPv4 endpoints.
  • You cannot attach a security group, but you can monitor with CloudWatch metrics such as BytesOutToDestination, ErrorPortAllocation and PacketsDropCount.

Reducing NAT costs

TechniqueEffect
Gateway endpoints for S3 and DynamoDBFree; removes that traffic from NAT
Interface endpoints for ECR, Secrets Manager, SQS, etc.Cheaper than per-GB NAT at scale
Keep chatty tiers in the same AZ as their NAT GatewayAvoids cross-AZ charges
Use IPv6 + egress-only IGWNo NAT charge
Cache/mirror packages internallyFewer internet downloads

Common failure causes

  • NAT Gateway placed in a private subnet (it needs an IGW route).
  • Missing 0.0.0.0/0 route in the private route table.
  • No Elastic IP, or the IGW is not attached.
  • NACL blocks the return ephemeral ports (1024–65535).

Real World Example

Scenario — a healthcare analytics firm cuts a $14,000-a-month NAT bill.

The firm runs batch processing in private subnets across three AZs. Initially they deployed one NAT Gateway in AZ-a for all three AZs. When AZ-a had an incident, the other two AZs lost internet access and jobs failed. They also noticed a large bill: nodes pulled terabytes of data from S3 and container images from ECR through the NAT Gateway, paying per-GB processing, plus cross-AZ charges for AZ-b and AZ-c traffic.

The fix:

  • Deploy one NAT Gateway per AZ with matching per-AZ private route tables, removing the single point of failure and cross-AZ transfer.
  • Add a gateway endpoint for S3 (free) and interface endpoints for ECR and CloudWatch Logs.
  • Keep NAT only for the few external vendor APIs.

NAT data-processing volume dropped by about 85%, the monthly bill fell substantially, and an AZ outage now affects only the workloads in that AZ.

Architecture Diagram

One NAT Gateway per AZ with a zonal private route table
Architecture
VPC 10.0.0.0/16
AZ A
Public A
NAT Gateway AEIP
Private A
Workers A0.0.0.0/0 -> NAT A
AZ B
Public B
NAT Gateway BEIP
Private B
Workers B0.0.0.0/0 -> NAT B
Internet Gateway
S3 gateway endpointfree
Internet
Amazon S3

Each AZ's private subnet uses the NAT Gateway in its own AZ; S3 traffic bypasses NAT through a gateway endpoint.

  1. 1Workers in a private subnet send 0.0.0.0/0 traffic to the NAT Gateway in their own AZ.
  2. 2The NAT Gateway translates the source to its Elastic IP and forwards the packet to the Internet Gateway.
  3. 3Replies return to the Elastic IP and are translated back to the private instance.
  4. 4S3 traffic uses the gateway endpoint route and never touches NAT, saving data-processing cost.

Best Practices

  • ✓Deploy a NAT Gateway in every AZ you use and give each AZ its own private route table.
  • ✓Always put the NAT Gateway in a public subnet with an Elastic IP and a route to the IGW.
  • ✓Use gateway and interface VPC endpoints to keep AWS service traffic off the NAT Gateway.
  • ✓Monitor BytesOutToDestination, ErrorPortAllocation and PacketsDropCount with CloudWatch alarms; use Flow Logs to find top talkers.
  • ✓Use a single NAT Gateway only in dev/test, accepting the AZ-failure risk to save cost.
  • ✓Restrict egress further with Network Firewall or proxy allow-lists when compliance requires domain-level control.
  • ✓Use IPv6 and an Egress-only IGW for outbound-only dual-stack workloads to avoid NAT charges.
  • ✓Choose a NAT instance only intentionally (very low traffic, need security groups or port forwarding) and automate its recovery.

Common Interview Questions

Exam Tips

SAA-C03 focus

  • NAT Gateway = managed, public subnet, Elastic IP, outbound IPv4 only. Memorise this for "private instances need internet".
  • Zonal: multi-AZ resilience requires one NAT Gateway per AZ; a single NAT in one AZ is the classic wrong answer for HA.
  • Bandwidth 5 Gbps scaling to 100 Gbps; NAT instances are limited by instance type.
  • NAT Gateways do not support security groups; NAT instances do and need source/destination check disabled.
  • Cost-optimisation: use VPC endpoints (S3/DynamoDB gateway endpoints are free) to bypass NAT data-processing charges.
  • NAT Gateway cannot be used as a bastion or for inbound port forwarding.
  • IPv6 outbound-only -> Egress-only IGW, not NAT Gateway.
  • A NAT Gateway in a private subnet (public NAT) will not work — it needs an IGW route.

Finished this lesson?

0 of 64 lessons done · 0% of the course