When Should You Use a NAT Gateway vs an Egress-Only IGW?

Amazon EC2 instances deployed in private subnets require specialized gateway components to initiate outbound connections to the internet while blocking unsolicited inbound traffic. Choosing between a NAT Gateway and an Egress-Only Internet Gateway depends primarily on the IP protocol version in use. A NAT Gateway handles IPv4 traffic by translating private IPv4 addresses into a public IPv4 address, whereas an Egress-Only Internet Gateway is designed exclusively for IPv6 traffic, allowing outbound communication using globally unique IPv6 addresses without performing network address translation.

Understanding the Core Difference: IPv4 vs. IPv6

The fundamental distinction between these two Amazon VPC components lies in how IPv4 and IPv6 addressing operate inside a Virtual Private Cloud.

In an IPv4 network, private subnets use RFC 1918 private address ranges (such as 10.0.0.0/16) that are not routable on the public internet. For an EC2 instance with only a private IPv4 address to download software updates or call external APIs, a device must translate its private source IP into a public IPv4 address.

In an IPv6 network, every IPv6 address assigned to an Amazon EC2 instance by AWS is a globally unique, publicly routable unicast address. Because there is no concept of private versus public IPv6 addresses in standard VPC configurations, address translation is unnecessary. However, you still need a mechanism to allow instances in private subnets to reach the internet while preventing external hosts from initiating connections to those instances.

When to Use an AWS NAT Gateway

You should use a NAT Gateway when your EC2 instances in private subnets communicate over IPv4 and need outbound internet access or connectivity to other VPCs and on-premises networks.

Key Characteristics of a NAT Gateway

  • IPv4 Support: Built specifically to perform Network Address Translation for IPv4 traffic (and NAT64 when paired with DNS64 to allow IPv6-only instances to reach IPv4-only destinations).
  • Subnet Placement: A public NAT Gateway must be deployed inside a public subnet that has a route to a standard Internet Gateway (IGW). It requires an Elastic IP (EIP) address.
  • Stateful Inspection: It tracks outbound connections initiated by private instances and only forwards return traffic matching an active session, dropping unsolicited inbound requests.
  • Availability Zone Scope: A NAT Gateway is zonal. For high availability, you deploy one NAT Gateway per Availability Zone and configure private route tables in each zone to point to their local NAT Gateway.
  • Pricing: AWS charges an hourly rate for each provisioned NAT Gateway plus a per-gigabyte data processing fee. If your monthly uptime is \(T\) hours and total data processed is \(D\) gigabytes, the cost \(C_{\text{NAT}}\) follows: \[C_{\text{NAT}} = (R_{\text{hourly}} \times T) + (R_{\text{data}} \times D)\]

Common Use Cases for a NAT Gateway

  1. IPv4-Only Private Subnets: Your application runs on an IPv4-only VPC architecture and needs to fetch OS patches, container images, or third-party webhooks.
  2. Allowlisting Static Source IPs: External partners require a fixed IPv4 address to allowlist your outbound API calls. Because a public NAT Gateway uses an Elastic IP, all private instances routing through it share that predictable public IPv4 address.
  3. NAT64 Workloads: You run IPv6-only private subnets, but your instances occasionally need to communicate with legacy external services that only resolve to IPv4 addresses.

When to Use an Egress-Only Internet Gateway

You should use an Egress-Only Internet Gateway when your EC2 instances in private subnets use IPv6 addresses and need outbound access to IPv6-enabled destinations on the internet without allowing inbound IPv6 connections.

Key Characteristics of an Egress-Only Internet Gateway

  • IPv6 Exclusive: Works strictly with IPv6 traffic (::/0). It does not support IPv4 traffic or perform network address translation.
  • VPC-Level Attachment: Unlike a NAT Gateway, an Egress-Only Internet Gateway is not placed inside a public subnet. It attaches directly to the VPC, is horizontally scaled, redundant, and highly available across all Availability Zones by default.
  • Stateful Filtering Without Translation: It forwards outbound IPv6 packets using the instance's own IPv6 address and allows the corresponding response packets back in, while blocking any new inbound connection attempts originating from the internet.
  • Pricing: There is no hourly charge or gateway data processing fee for an Egress-Only Internet Gateway; you only pay standard AWS data transfer egress rates.

Common Use Cases for an Egress-Only Internet Gateway

  1. IPv6-Only Private Subnets Connecting to IPv6 Endpoints: Your private workloads communicate exclusively with modern IPv6-enabled services, package repositories, or AWS endpoints over IPv6.
  2. Cost Optimization in Dual-Stack Environments: By configuring your dual-stack EC2 instances to prefer IPv6 for outbound traffic, requests to IPv6-capable internet destinations route through the free Egress-Only Internet Gateway instead of incurring per-gigabyte processing charges on a NAT Gateway.
  3. Simplified Multi-AZ Architecture: Because a single Egress-Only Internet Gateway spans the entire VPC automatically, you do not need to manage per-AZ gateway deployments or Elastic IPs for your IPv6 outbound routing.

Side-by-Side Comparison

Feature NAT Gateway (Public) Egress-Only Internet Gateway
Supported Protocol IPv4 (and NAT64 for IPv6-to-IPv4) IPv6 only
Address Translation Translates private IPv4 to Elastic IP No translation (uses instance IPv6)
Deployment Scope Zonal (deployed inside a public subnet) Regional / VPC-wide
Requires Internet Gateway Yes (NAT Gateway routes through IGW) No (acts as a specialized IGW itself)
Requires Elastic IP Yes No
Gateway Cost Hourly charge + per-GB processing fee Free (standard data transfer fees apply)

Routing Configuration in Dual-Stack Private Subnets

In many production environments, private subnets are configured as dual-stack, meaning EC2 instances receive both a private IPv4 address and a public IPv6 address. In this scenario, you use both gateways simultaneously in the private subnet's route table:

  • IPv4 Default Route (0.0.0.0/0): Point this route to the NAT Gateway ID (nat-xxxxxxxx) located in a public subnet.
  • IPv6 Default Route (::/0): Point this route to the Egress-Only Internet Gateway ID (eigw-xxxxxxxx) attached to the VPC.

When an EC2 instance initiates an outbound request, the operating system's DNS resolver and network stack determine whether to use IPv6 or IPv4. Traffic destined for an IPv6 address follows the ::/0 route through the Egress-Only Internet Gateway at zero gateway processing cost, while traffic destined for an IPv4 address follows the 0.0.0.0/0 route through the NAT Gateway.