How are NAT gateway charges structured, and why does AWS service traffic end up paying them?
A NAT gateway has two charges of its own. The first is an hourly fee for each gateway. Because a gateway lives in a single Availability Zone, a highly available setup with one gateway per AZ multiplies that fee by the number of AZs. The second is a per-GB data processing charge on every byte the gateway handles, in both directions. A 10 GB download costs the same processing fee as a 10 GB upload, and the destination does not matter.
Standard data transfer charges come on top of these. Internet egress is billed as data transfer out. An instance that sends traffic to a NAT gateway in a different AZ also pays cross-AZ transfer before the NAT processing fee applies. Rates differ by region and change over time, so check the current figures on the AWS pricing page rather than relying on numbers from older posts.
Why AWS API traffic goes through the NAT
S3, DynamoDB, ECR, CloudWatch, STS and SQS are reached through public regional hostnames by default. From a private subnet, the SDK resolves those names to public IP addresses. The route table has no more specific route for those addresses, so the traffic matches 0.0.0.0/0 and goes to the NAT gateway.
The traffic stays inside AWS's network the whole way, yet every byte is billed as NAT processing. This adds up quickly for high-volume traffic: S3 reads and writes, log shipping, and ECR image pulls, whose layers are served from S3. That gives the angle for the rest of this article: a large share of a typical NAT bill is processing on traffic that never needed a NAT.
+--------------------------------- VPC ---------------------------------+
| AZ-a AZ-b |
| +------------------------+ +------------------------+ |
| | Private subnet | | Private subnet | |
| | app calls S3, ECR, ... | | app instance | |
| | rt 0.0.0.0/0 -> NAT | | rt 0.0.0.0/0 -> NAT | |
| +-----------+------------+ | (NAT is in AZ-a) | |
| | +-----------+------------+ |
| | | |
| |<--- (c) cross-AZ data transfer ---+ |
| v |
| +------------------------+ |
| | Public subnet | (a) hourly fee per gateway, per AZ |
| | NAT gateway | (b) per-GB processing, both ways |
| +-----------+------------+ |
+--------------|--------------------------------------------------------+
v
+-------------+
| Internet GW |
+------+------+
|
+----------------------------------+
v v
+-----------------------------+ +---------------------------+
| AWS public endpoints | | Internet |
| S3 DynamoDB ECR CloudWatch | | (d) data transfer out |
| STS SQS (public IPs) | +---------------------------+
| (b) still applies per GB |
+-----------------------------+
By default, private-subnet calls to AWS service endpoints follow the 0.0.0.0/0 route through the NAT gateway, so they pick up the hourly fee (a) and the per-GB processing charge (b), plus cross-AZ transfer (c) when the NAT sits in another AZ; internet-bound traffic also pays data transfer out (d).
How do you find out which traffic is driving your NAT gateway bill?
Before adding endpoints, confirm which flows dominate. Guessing wastes effort: a team can spend a sprint on interface endpoints for low-volume services while one bulk S3 job accounts for most of the bill.
Flow logs on the NAT gateway's network interface
Enable VPC Flow Logs on the elastic network interface that belongs to the NAT gateway. Every byte the gateway processes passes through that interface. Aggregate bytes by destination address over a representative window that covers batch jobs and deploys. Athena over flow logs in S3 works well for this, and so does CloudWatch Logs Insights. Then map the top destinations to services using AWS's published ip-ranges.json, which tags CIDR blocks by service and region. Use longest-prefix matching. Many ranges appear under both the generic AMAZON tag and a specific service such as S3, and the more specific tag is the useful one.
This approach has costs and limits:
- Cost: flow log ingestion and storage are billed. Delivering to S3 is usually cheaper than CloudWatch Logs. Collect logs for a bounded period rather than leaving them on permanently.
- Accuracy: IP-to-service mapping is approximate. Some ranges are shared across services, and the file changes over time. Treat the results as a ranking of where traffic goes, not an exact accounting.
Cost Explorer by usage type
Group Cost Explorer by usage type to separate NatGateway-Hours from NatGateway-Bytes. Hourly charges call for consolidating gateways. Byte charges call for rerouting traffic. Also check DataTransfer-Regional-Bytes, which reveals cross-AZ transfer, including workloads that send traffic to a NAT gateway in another AZ.
Once you have both views, start with the largest flow and move down the list.
import csv, ipaddress, json, sys
from collections import defaultdict
# Usage: python3 -I map_destinations.py ip-ranges.json top_destinations.csv
# CSV columns: dstaddr,bytes (e.g. exported from an Athena query that sums
# bytes by dstaddr over the NAT gateway ENI's flow logs). Feed it the top N rows.
ranges_path, flows_path = sys.argv[1], sys.argv[2]
with open(ranges_path) as f:
data = json.load(f)
# IPv4 prefixes only; extend with data["ipv6_prefixes"] if you route IPv6 egress
nets = [(ipaddress.ip_network(p["ip_prefix"]), p["service"], p["region"])
for p in data["prefixes"]]
def lookup(ip):
addr = ipaddress.ip_address(ip)
best = None
for net, service, region in nets: # linear scan is fine for a top-N list
if addr in net:
# Longest prefix wins; on a tie prefer a specific tag (S3, DYNAMODB...)
# over the generic AMAZON tag that duplicates many ranges
key = (net.prefixlen, service != "AMAZON")
if best is None or key > best[0]:
best = (key, service, region)
return (best[1], best[2]) if best else ("NON-AWS", "-")
totals = defaultdict(int)
with open(flows_path) as f:
for row in csv.DictReader(f):
totals[lookup(row["dstaddr"])] += int(row["bytes"])
# Largest flows first: this ranking is where endpoint work should start.
# Treat it as approximate; shared ranges and file updates blur attribution.
for (service, region), b in sorted(totals.items(), key=lambda kv: -kv[1]):
print(f"{service:<20} {region:<16} {b / 1e9:10.2f} GB")
A Python script that takes per-destination byte totals from NAT gateway flow logs, maps each IP to an AWS service and region with longest-prefix matching against ip-ranges.json, and ranks services by bytes so the largest flows get addressed first.
How do gateway VPC endpoints for S3 and DynamoDB cut egress costs?
For many accounts, the largest flow is S3, and the fix costs nothing to run. A gateway VPC endpoint has no hourly charge and no per-GB charge. It adds a route to each route table you associate with it. The route's destination is the AWS-managed prefix list for the service, and its target is the endpoint. Route selection uses longest-prefix match, so the prefix-list route wins over the 0.0.0.0/0 route to the NAT gateway. S3 traffic then goes to the endpoint and is never processed by NAT.
The route exists only in route tables that are associated with the endpoint. Each private subnet's route table must be associated, or that subnet's S3 traffic keeps going through NAT. Workloads that usually benefit most are data pipelines, backups, log shipping to S3, and artifact or package pulls from buckets.
Illustrative estimate (assumed numbers, not a benchmark): monthly savings = GB of S3/DynamoDB traffic through NAT × NAT per-GB processing rate. If you assume 10,000 GB and $0.045/GB, the savings are $450 per month. Use your own region's rate.
The limits:
- Gateway endpoints support only S3 and DynamoDB.
- They cover only access to resources in the same region. Reads from a bucket in another region still go through NAT or another path.
To create one, run aws ec2 create-vpc-endpoint with --vpc-endpoint-type Gateway, --service-name com.amazonaws.<region>.s3, and --route-table-ids. To confirm it worked, run aws ec2 describe-route-tables on each associated table. You should see a route whose destination is a pl- prefix list and whose target is the vpce- ID.
#!/usr/bin/env bash
set -euo pipefail
# Placeholder values: replace with your own VPC, region and private route tables.
REGION="us-east-1"
VPC_ID="vpc-0abc1234def567890"
# Every private route table that sends S3 traffic through NAT must be listed here.
ROUTE_TABLES="rtb-0aaa1111bbbb22223 rtb-0ccc3333dddd44445"
# Create the S3 gateway endpoint. Gateway endpoints have no hourly or per-GB charge.
# AWS adds a prefix-list route (pl-...) to each listed route table.
ENDPOINT_ID=$(aws ec2 create-vpc-endpoint \
--region "$REGION" \
--vpc-id "$VPC_ID" \
--vpc-endpoint-type Gateway \
--service-name "com.amazonaws.${REGION}.s3" \
--route-table-ids $ROUTE_TABLES \
--query 'VpcEndpoint.VpcEndpointId' --output text)
echo "Created endpoint: $ENDPOINT_ID"
# Verify: each associated table should have a route whose destination is the
# S3 prefix list and whose target is the endpoint, alongside 0.0.0.0/0 -> NAT.
for RTB in $ROUTE_TABLES; do
echo "--- $RTB"
aws ec2 describe-route-tables \
--region "$REGION" \
--route-table-ids "$RTB" \
--query 'RouteTables[0].Routes[].[DestinationCidrBlock,DestinationPrefixListId,GatewayId,NatGatewayId,State]' \
--output table
done
# To add a route table you missed later, associate it instead of recreating the endpoint:
# aws ec2 modify-vpc-endpoint --vpc-endpoint-id "$ENDPOINT_ID" --add-route-table-ids rtb-0eee5555ffff66667
This script creates an S3 gateway endpoint associated with each private route table, then lists each table's routes so you can confirm a pl- prefix-list route targeting the vpce- ID appears next to the 0.0.0.0/0 NAT route.
When are interface VPC endpoints worth paying for, and when should you avoid them?
Interface endpoints (PrivateLink) are billed differently from gateway endpoints. Each endpoint has an hourly charge per AZ it is deployed in, plus a per-GB processing charge. NAT also has a per-GB charge, so an interface endpoint saves money only when the per-GB difference across your traffic volume exceeds the fixed hourly cost.
Illustrative estimate. These are placeholder rates, not measured or current AWS prices; check your region's pricing. Assume an endpoint costs $0.01/hour per AZ and $0.01/GB processed, NAT processing is $0.045/GB, there are 3 AZs, and a month is 730 hours.
- Fixed cost per endpoint: 3 × 730 × $0.01 = $21.90/month
- Savings per GB moved off NAT: $0.045 − $0.01 = $0.035
- Break-even for CloudWatch Logs: $21.90 ÷ $0.035 ≈ 626 GB/month
- ECR needs two interface endpoints (
ecr.apiandecr.dkr), so its fixed cost and break-even volume roughly double.
| Scenario (illustrative) | Endpoint cost/month | NAT cost/month |
|---|---|---|
| 1 VPC, Logs, 2,000 GB | ~$42 | ~$90 |
| 10 VPCs × 5 services, 50 GB total | ~$1,095 | ~$2.25 |
The second row shows the common trap. When teams add endpoints for every service in every VPC, the fixed per-AZ charges multiply while traffic stays low. NAT is cheaper in that case.
Private DNS also needs care. When you enable it, the public service hostname resolves to the endpoint's private IPs, but only for queries that reach that VPC's Route 53 Resolver. Custom DNS servers that forward queries elsewhere never get the override, so traffic keeps flowing through NAT and nothing reports an error. On-premises clients need forwarding through a Resolver inbound endpoint. For endpoints shared across VPCs, private DNS applies only in the VPC that owns the endpoint. Consumer VPCs need a private hosted zone associated with them.
Why do container image pulls inflate NAT costs, and how do you route them correctly?
Image pulls are often one of the largest NAT line items because the data is heavy and repeated. Every new node, autoscaling event, or uncached deployment downloads full image layers again. A single ECR pull is not a single flow, though. It is three, and each one needs its own route.
ECR stores image layers in S3. The registry returns redirects to S3 for the layer blobs, so the bulk of the bytes travels over the S3 gateway endpoint if one is attached to the subnet's route table. If your S3 endpoint policy restricts buckets, it must also allow the AWS-managed bucket that ECR uses for layers. Otherwise pulls fail at the layer download step.
The rest of the pull is small authenticated calls: GetAuthorizationToken and other ECR API calls, plus Docker registry protocol requests for manifests. Without the ecr.api and ecr.dkr interface endpoints, these still go through NAT. The volume is low, but it keeps a NAT dependency in place, so a private subnet still cannot pull images when NAT is down.
Public registries are a different case. Images from Docker Hub, GitHub, or Quay come from the internet and need NAT or another egress path. An ECR pull-through cache rule changes this. ECR fetches from the upstream registry, and your nodes pull the cached copy through the private paths above.
| Request type | Path without endpoints | Path with endpoints |
|---|---|---|
| ECR auth/API calls | NAT | ecr.api interface endpoint |
| Registry manifests | NAT | ecr.dkr interface endpoint |
| ECR layer blobs | NAT | S3 gateway endpoint |
| Public registry pulls | NAT | NAT, or pull-through cache via ECR |
To estimate the NAT data processing charge for layer traffic, multiply image size × pulls per day × days × the NAT per-GB processing rate.
What are the alternatives for cross-AZ and true internet egress paths?
The traffic left on NAT after endpoints are in place is either cross-AZ hops or genuine internet egress. Each egress design trades hourly charges against per-GB charges and operational risk.
| Design | Saves | Adds | Main risk |
|---|---|---|---|
| Single NAT gateway | Hourly charges for extra gateways | Cross-AZ transfer from every other AZ | One AZ failure cuts egress for all AZs |
| NAT gateway per AZ | Cross-AZ transfer | One hourly charge per AZ | Higher fixed cost |
| Centralized egress VPC (Transit Gateway or peering) | Duplicate NATs and interface endpoints across VPCs | Attachment, Transit Gateway processing, cross-AZ hops | Shared blast radius |
| Public IPs or self-managed NAT instances | NAT gateway hourly and processing fees | Patching, scaling, failover, larger attack surface | Team owns availability and security |
To choose between one NAT and one per AZ, compare two monthly figures: the hourly cost of the extra gateways, and the GB that would cross AZs to reach a single gateway multiplied by the inter-AZ rate. If the cross-AZ volume is small and a single-AZ egress outage is acceptable, as in many dev environments, one NAT is enough. Production workloads usually justify per-AZ gateways for fault isolation alone.
NAT bills per GB processed, so internet egress shrinks only if fewer bytes leave the VPC. Several techniques help:
- Package mirrors for OS and language dependencies keep repeated build downloads inside the VPC.
- Pull-through caches let only the first pull of a public image traverse NAT.
- Compression of outbound payloads reduces the bytes NAT processes.
- Batching outbound calls cuts per-request header and TLS handshake overhead.
How should you roll out endpoints and policies without breaking access?
A staged rollout sequence
- Baseline with flow logs. Record bytes per destination for a full business cycle. Without that baseline you cannot attribute later savings to a specific change.
- Add the gateway endpoints for S3 and DynamoDB. They cost nothing and only add routes to the selected route tables. Associate them with every private subnet's route table, not just one.
- Re-measure. Confirm that NAT bytes to those service prefixes dropped. If they didn't, a route table was probably missed.
- Evaluate interface endpoints one service at a time against your break-even estimate. Adding them in bulk hides which ones pay for themselves.
- Alert on regressions. Set an AWS Budgets threshold or a Cost Anomaly Detection monitor scoped to the NAT gateway data-processing usage type. A new service, or a routing change that bypasses an endpoint, then shows up within days instead of on the next invoice.
Policies that can lock people out
Endpoint policies and bucket policies are where this rollout usually breaks things. A common hardening step is a bucket policy that denies requests unless they arrive through your endpoint, using a condition such as "StringNotEquals": {"aws:SourceVpce": "vpce-0abc123"}.
That deny applies to every request that does not come through that endpoint, which includes:
- console users browsing the bucket
- CI runners outside the VPC
- partner or other accounts reading through their own endpoints
Stage the change:
- Apply it to a non-critical bucket first.
- Carve out break-glass and pipeline roles with an
aws:PrincipalArnexception. - Watch CloudTrail access-denied events before you widen the scope.
Endpoint policies fail the same way. If an endpoint policy is scoped to your own buckets, it silently blocks third-party buckets your workloads depend on.
Who benefits most
The biggest returns go to:
- teams running S3-heavy data pipelines
- container platforms that pull images constantly
- multi-AZ private workloads, where AWS-bound traffic previously flowed through NAT by default
#!/usr/bin/env bash
# Stage 1: apply the endpoint-only policy to a NON-CRITICAL bucket first.
set -euo pipefail
BUCKET="example-staging-artifacts"
VPCE_ID="vpce-0abc123def4567890"
ACCOUNT_ID="111122223333"
# Deny all S3 actions unless BOTH are true:
# - the request did not arrive through our gateway endpoint
# - the caller is not one of the carved-out roles
# Condition operators in one block are ANDed, so the excepted roles still
# work from the console or from CI runners outside the VPC.
# Requests that do not come through an endpoint have no aws:SourceVpce key.
# StringNotEquals treats a missing key as a match, so those requests are denied.
cat > /tmp/bucket-policy.json <<EOF
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "DenyUnlessViaVpceOrExceptedRole",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": ["arn:aws:s3:::${BUCKET}", "arn:aws:s3:::${BUCKET}/*"],
"Condition": {
"StringNotEquals": { "aws:SourceVpce": "${VPCE_ID}" },
"ArnNotLike": { "aws:PrincipalArn": [
"arn:aws:iam::${ACCOUNT_ID}:role/break-glass-admin",
"arn:aws:iam::${ACCOUNT_ID}:role/ci-deploy"
]}
}
}]
}
EOF
# Apply the policy as the break-glass role so you cannot lock yourself out.
aws s3api put-bucket-policy --bucket "$BUCKET" --policy file:///tmp/bucket-policy.json
aws s3api get-bucket-policy --bucket "$BUCKET" --query Policy --output text
# Next: watch CloudTrail AccessDenied events for this bucket before widening scope.
A staged S3 bucket policy that denies access unless the request comes through a specific VPC endpoint, with aws:PrincipalArn exceptions for break-glass and CI roles so console and out-of-VPC pipelines are not locked out.
How OneEnv can help
Disclosure: OneEnv is the product behind this blog.
OneEnv (oneenv.io) is a workspace-based governance platform for the things services share — environment variables, database structure, API routes and validation rules. A change to a shared value is staged on a branch, reviewed once, and then every affected service explicitly approves or rejects it before it goes live, so you can see who a change touches before it ships instead of finding out in production.
Applied to aws nat gateway cost reduction, this is where it helps:
Saves time
- Every service that inherits a shared value is listed in one place, so nobody searches repos and chats to find out who is affected.
- One review per branch replaces coordinating each team separately; each service still keeps its own approve/reject.
- Reviewers see the exact diff and the list of affected services up front, so approval is a decision rather than an investigation.
Saves cost
- Fewer production incidents and rollbacks caused by a shared value, route or column changing under a consumer unannounced.
- Less duplicated configuration to maintain: one shared definition inherited by many services.
- Per-service approve/reject means a bad shared value can be refused where it would break something, before it is live.
- OneEnv has a free plan (1 workspace, unlimited services and members, full governance), so trying it costs nothing.
These are qualitative benefits, not measured results — how much you save depends on how many services share the value.
Want to try it? Start at oneenv.io.