How is NAT Gateway pricing structured, and why do bills spike?
A NAT Gateway bills on two separate meters, and standard data transfer charges apply on top of both.
| Charge | What triggers it | Scales with | Typical surprise factor |
|---|---|---|---|
| Hourly fee | Each provisioned gateway, every hour it exists | Number of gateways (usually one per AZ) | Low: predictable and flat |
| Data processing fee | Every GB that passes through the gateway, in either direction | Traffic volume | High: grows with workload |
| Data transfer | Normal AWS transfer rules, such as internet egress or cross-AZ traffic | Destination and path | Medium: depends on topology |
The hourly fee is easy to forecast. Three AZs with one gateway each costs the same every month whether the gateways are idle or busy.
The processing fee causes the spikes. AWS charges it on every byte the gateway handles, and it does not matter where that byte is going. Consider a container in a private subnet that pulls an image from ECR, writes objects to S3, or ships logs to CloudWatch. It reaches those public service endpoints through the NAT Gateway, so each GB is billed as processed. This happens even when the transfer to that service in the same region would otherwise be free or cheap. A deploy that pulls large images across hundreds of tasks, or a batch job reading terabytes from S3, can move the bill more than the gateways' hourly cost does.
Rates vary by region and change over time. Check the current VPC pricing page for your regions before you model anything.
This matters most for teams that run workloads in private subnets and call AWS services at high volume. Common examples are S3, ECR, DynamoDB, CloudWatch Logs, STS and SQS. For these teams, much of the NAT processing spend pays for traffic that never needed to leave the AWS network.
How do you find out what is driving your NAT Gateway bytes?
Start with billing data, because it shows whether there is a problem worth investigating. In Cost Explorer, NAT charges appear under EC2-Other. Group by usage type to split the two components: NatGateway-Hours is the fixed per-gateway charge, and NatGateway-Bytes is data processing. In the Cost and Usage Report, these usage types carry a region prefix and a resource ID, so you can see which gateway, and therefore which AZ and VPC, is processing the bytes. If hours dominate, endpoints will not help much. If bytes dominate, keep going.
Next, find out where those bytes go. Enable VPC Flow Logs on the NAT gateway's network interface, or on the private subnets that route through it. Use a custom format that includes pkt-srcaddr and pkt-dstaddr, because the standard fields on the NAT ENI show the gateway's own addresses rather than the original workload and destination. Deliver the logs to S3, query them with Athena, and sum bytes by destination address. Then match the top destinations against AWS's published IP ranges file, which tags each prefix with a service and region.
The usual heavy hitters are:
- Direct S3 traffic
- ECR image pulls, whose layers are served from S3
- CloudWatch Logs and metrics
- DynamoDB
- API calls to SSM, STS and Secrets Manager
The investigation has its own cost. You pay for flow log delivery, storage and Athena scans. Limit collection to 24–48 hours that include a known peak, or to a representative subset of subnets. Then turn it off.
#!/usr/bin/env bash
# Time-boxed flow log capture on a NAT gateway's ENI, delivered to S3 for Athena.
set -euo pipefail
NAT_ID="nat-0123456789abcdef0" # placeholder NAT gateway ID
BUCKET_ARN="arn:aws:s3:::example-flowlogs-bucket/nat-investigation/"
# Look up the network interface that belongs to the NAT gateway.
ENI_ID=$(aws ec2 describe-nat-gateways \
--nat-gateway-ids "$NAT_ID" \
--query 'NatGateways[0].NatGatewayAddresses[0].NetworkInterfaceId' \
--output text)
# Custom format: pkt-srcaddr/pkt-dstaddr show the original workload and
# destination. srcaddr/dstaddr on the NAT ENI show the gateway's own addresses.
# Single quotes stop the shell from expanding ${...}.
FORMAT='${start} ${end} ${interface-id} ${flow-direction} ${srcaddr} ${dstaddr} ${pkt-srcaddr} ${pkt-dstaddr} ${dstport} ${protocol} ${packets} ${bytes}'
FLOW_LOG_ID=$(aws ec2 create-flow-logs \
--resource-type NetworkInterface \
--resource-ids "$ENI_ID" \
--traffic-type ALL \
--log-destination-type s3 \
--log-destination "$BUCKET_ARN" \
--log-format "$FORMAT" \
--max-aggregation-interval 600 \
--query 'FlowLogIds[0]' --output text)
echo "Capturing on $ENI_ID with flow log $FLOW_LOG_ID"
# Remove the flow log when the 24-48 hour window, including a known peak, ends.
# Delivery and storage cost keeps running until you do this:
# aws ec2 delete-flow-logs --flow-log-ids "$FLOW_LOG_ID"
# Also add an S3 lifecycle rule on the prefix so the raw logs expire.
Finds a NAT gateway's network interface, enables a custom-format VPC Flow Log on it that records the original packet source and destination addresses to S3, and shows the command to delete the flow log at the end of the capture window.
How do gateway and interface VPC endpoints work?
VPC endpoints remove traffic from the NAT path. AWS offers two kinds, and they work and bill very differently.
A gateway endpoint exists only for S3 and DynamoDB. It adds no network interface to your VPC. Instead, it adds a route to a managed prefix list of the service's public IP ranges. Because that route is more specific than 0.0.0.0/0, matching traffic skips the NAT gateway. Gateway endpoints have no hourly or per-GB charge. They have two limits. First, they only carry traffic to the same region, so a bucket in another region is still reached through NAT. Second, they only affect the route tables you associate them with, so a private route table you miss keeps sending traffic through NAT.
An interface endpoint (PrivateLink) places an ENI in each subnet you choose. With private DNS enabled, the service's standard hostname resolves to those ENI addresses, so SDKs and CLIs switch over without code changes. You pay an hourly fee for each endpoint in each AZ, plus a per-GB processing fee.
Each service needs its own endpoint. ECR, for example, needs the ecr.api and ecr.dkr interface endpoints plus the S3 gateway endpoint, because image layers are served from S3.
| Gateway endpoint | Interface endpoint | |
|---|---|---|
| Services | S3, DynamoDB | Most AWS services |
| Mechanism | Prefix-list route | ENI with private DNS |
| Hourly charge | None | Per endpoint, per AZ |
| Per-GB charge | None | Yes |
| Scope | Same region, associated route tables | Subnets with an ENI |
Traffic paths in each AZ (one NAT gateway and one endpoint ENI per AZ):
- Workload →
0.0.0.0/0route → NAT gateway → internet gateway → service. You pay NAT hourly and per-GB charges. - Workload → prefix-list route → gateway endpoint → S3 or DynamoDB. There is no endpoint charge.
- Workload → private DNS → interface endpoint ENI in the same AZ → PrivateLink → service. You pay endpoint hourly and per-GB charges.
One AZ shown. Each AZ has its own NAT gateway and interface endpoint ENIs.
+-----------------------------------------------+
| Workload in private subnet (one AZ) |
+-----------------------------------------------+
| | |
| 0.0.0.0/0 | S3/DDB prefix | private DNS
| route | list route | resolves to ENI
v v v
+-------------+ +-------------+ +-------------+
| NAT gateway | | Gateway | | Interface |
| (one per AZ)| | endpoint | | endpoint ENI|
| | | (route only)| | (one per AZ)|
+------+------+ +------+------+ +------+------+
| | |
v | |
+-------------+ | |
| Internet | | |
| gateway | | |
+------+------+ | |
v v v
+-------------+ +-------------+ +-------------+
| AWS service | | S3 or | | AWS service |
| public | | DynamoDB, | | via |
| endpoint | | same region | | PrivateLink |
+-------------+ +-------------+ +-------------+
NAT hourly + No endpoint Hourly per AZ +
per-GB charge per-GB
Traffic paths from a private workload in one AZ: through the NAT and internet gateways, through the S3/DynamoDB gateway endpoint by prefix-list route, and through an interface endpoint ENI via private DNS, with each path's charges.
When does an interface endpoint pay for itself? A break-even calculation
Illustrative estimate. The rates below are assumed inputs chosen for easy arithmetic. Substitute your region's published prices.
Assume:
- NAT data processing: P_nat = $0.045/GB
- Interface endpoint hourly charge: H = $0.01 per endpoint per AZ
- Endpoint data processing: P_ep = $0.01/GB
- N = 3 AZs, 730 hours per month
The NAT Gateway's own hourly charge is left out. You keep paying it for other egress, so the endpoint doesn't remove it.
For G GB per month of one service's traffic, the two options cost:
- NAT: P_nat × G
- Endpoint: (H × 730 × N) + (P_ep × G)
Set them equal and solve for break-even:
G* = (H × 730 × N) / (P_nat − P_ep)
With the assumed rates, the fixed endpoint cost is $21.90 per month. Dividing by the $0.035/GB saving gives G* ≈ 626 GB/month.
| Monthly GB | NAT cost | Endpoint cost (3 AZs) | Cheaper |
|---|---|---|---|
| 100 | $4.50 | $22.90 | NAT |
| 626 | $28.17 | $28.16 | Break-even |
| 2,000 | $90.00 | $41.90 | Endpoint |
| 10,000 | $450.00 | $121.90 | Endpoint |
The fixed term is charged per endpoint, per AZ, every hour, whether or not traffic flows. Consider a team that creates endpoints for 10 services, each carrying 50 GB per month:
- Through NAT: 500 GB costs $22.50.
- Through endpoints: $219 in hourly charges plus $5 in processing, for $224.
The bill rises by roughly $200 per month, and the AWS networking line looks "optimized" while costing more.
Reducing N lowers G*, but it also moves traffic across AZs and sacrifices zonal resilience. The reliable rule is to create an interface endpoint only when measured per-service volume clears G* with margin.
# Break-even calculator for one interface endpoint vs. NAT data processing.
# Illustrative estimate: rates are assumed inputs. Replace with your region's prices.
HOURS_PER_MONTH = 730
P_NAT = 0.045 # NAT Gateway data processing, $/GB (assumed)
H = 0.01 # interface endpoint hourly charge, $ per endpoint per AZ (assumed)
P_EP = 0.01 # interface endpoint data processing, $/GB (assumed)
N_AZ = 3 # AZs the endpoint is deployed in
def nat_cost(gb):
# NAT hourly charge is excluded: it remains for other egress either way.
return P_NAT * gb
def endpoint_cost(gb, endpoints=1):
# Fixed cost accrues per endpoint, per AZ, every hour, even with zero traffic.
fixed = H * HOURS_PER_MONTH * N_AZ * endpoints
return fixed + P_EP * gb
def break_even_gb():
# G* = (H * 730 * N) / (P_nat - P_ep)
return (H * HOURS_PER_MONTH * N_AZ) / (P_NAT - P_EP)
if __name__ == "__main__":
print(f"Break-even: {break_even_gb():.0f} GB/month per endpoint")
for gb in (100, 626, 2000, 10000):
nat, ep = nat_cost(gb), endpoint_cost(gb)
winner = "NAT" if nat < ep else "Endpoint"
print(f"{gb:>6} GB NAT ${nat:8.2f} Endpoint ${ep:8.2f} -> {winner}")
# Anti-pattern: 10 low-traffic services, 50 GB/month each.
services, gb_each = 10, 50
total_gb = services * gb_each
print(f"10 services via NAT: ${nat_cost(total_gb):.2f}")
print(f"10 services via endpoints: ${endpoint_cost(total_gb, services):.2f}")
A small Python calculator that solves the break-even formula G = (H × 730 × N) / (P_nat − P_ep) with assumed rates, reproduces the comparison table, and shows how ten low-traffic endpoints across three AZs cost more than routing the same traffic through NAT.*
How do you roll out VPC endpoints without breaking production?
Stage 1: Add endpoints alongside the NAT path
Start with gateway endpoints for S3 and DynamoDB. They add a prefix-list route to each route table you associate, and that route is more specific than 0.0.0.0/0, so matching traffic leaves the NAT path while everything else keeps using it. Associate every private route table that has a NAT default route. A missed table leaves that subnet's traffic on the NAT, and nothing reports the gap. Changing routes can reset in-flight connections, so apply the change during a quiet window.
Add interface endpoints next. Private DNS only resolves service hostnames to endpoint IPs when the VPC has both DNS support and DNS hostnames enabled. If either is off, clients keep resolving public IPs and keep going through the NAT. The endpoint's security group also has to allow inbound 443 from your workload subnets.
Stage 2: Verify the shift
In VPC flow logs, check that traffic to the service now goes to the gateway prefix list or to the endpoint ENI addresses instead of the NAT gateway's ENI. Then confirm that the NAT gateway's byte metrics in CloudWatch drop by roughly the volume you measured earlier. If they don't, look for an unassociated route table or for clients that hardcode regional endpoints.
Stage 3: Tighten policies in stages
Restrict access only after traffic is verified. Begin with permissive endpoint policies. Add aws:SourceVpce conditions to bucket policies one bucket at a time. Write explicit exceptions for console users, external CI runners and peered VPCs, because all of them reach S3 without going through your endpoint.
Stage 4: Alert
Set CloudWatch alarms on NAT byte metrics against your new baseline. This catches a new workload or a newly adopted service that quietly sends traffic back through the NAT.
#!/usr/bin/env bash
set -euo pipefail
REGION=us-east-1
VPC_ID=vpc-0abc1234def567890
NAT_ID=nat-0abc1234def567890
# Stage 1a: find every route table whose routes point at the NAT gateway, so none is missed.
RTBS=$(aws ec2 describe-route-tables --region "$REGION" \
--filters Name=vpc-id,Values="$VPC_ID" Name=route.nat-gateway-id,Values="$NAT_ID" \
--query 'RouteTables[].RouteTableId' --output text)
echo "Associating S3 gateway endpoint with: $RTBS"
# Gateway endpoint adds a prefix-list route to each table; the 0.0.0.0/0 NAT route stays in place.
aws ec2 create-vpc-endpoint --region "$REGION" --vpc-id "$VPC_ID" \
--vpc-endpoint-type Gateway --service-name "com.amazonaws.$REGION.s3" \
--route-table-ids $RTBS
# Stage 1b: private DNS for interface endpoints needs both VPC attributes on (one per call).
aws ec2 modify-vpc-attribute --vpc-id "$VPC_ID" --enable-dns-support '{"Value":true}'
aws ec2 modify-vpc-attribute --vpc-id "$VPC_ID" --enable-dns-hostnames '{"Value":true}'
# The security group must allow inbound 443 from workload subnets.
aws ec2 create-vpc-endpoint --region "$REGION" --vpc-id "$VPC_ID" \
--vpc-endpoint-type Interface --service-name "com.amazonaws.$REGION.ecr.api" \
--subnet-ids subnet-0aaa1111bbbb2222c subnet-0ddd3333eeee4444f \
--security-group-ids sg-0123456789abcdef0 --private-dns-enabled
# Stage 4: alarm when NAT traffic climbs back above the post-migration baseline.
# The threshold is a placeholder; set it from your own measured baseline.
aws cloudwatch put-metric-alarm --region "$REGION" \
--alarm-name "nat-bytes-above-baseline-$NAT_ID" \
--namespace AWS/NATGateway --metric-name BytesOutToDestination \
--dimensions Name=NatGatewayId,Value="$NAT_ID" \
--statistic Sum --period 3600 --evaluation-periods 3 \
--threshold 5000000000 --comparison-operator GreaterThanThreshold \
--alarm-actions arn:aws:sns:us-east-1:111122223333:nat-cost-alerts
An AWS CLI sequence that associates an S3 gateway endpoint with every route table pointing at the NAT gateway, enables VPC DNS attributes before creating an interface endpoint with private DNS, and adds a CloudWatch alarm on NAT bytes against a new baseline.
When should you avoid VPC endpoints, and where do they fail?
Endpoints only help for traffic to AWS services in the same region. A gateway endpoint for S3 covers buckets in the VPC's own region. Requests to a bucket in another region still leave through the NAT Gateway. Third-party SaaS APIs, public package registries, container images hosted outside AWS and any other internet destination have no endpoint at all. If your Stage 1 analysis shows that most NAT bytes go to these destinations, endpoints will not move the bill much.
Skip interface endpoints for low-volume services. Each one is billed per hour in every Availability Zone you deploy it to, whether or not traffic flows. A service that moves a few gigabytes a month costs more as an endpoint than it saves in NAT processing fees.
Most endpoint failures come from DNS. Private DNS only works if clients resolve the service name through the VPC resolver. If they don't, they get public IPs and route through NAT. Nothing errors. Traffic simply bypasses the endpoint, and the only signal is that NAT bytes don't drop.
| Symptom | Likely cause |
|---|---|
| NAT bytes unchanged after adding endpoint | Client uses a global hostname (e.g. global STS) that private DNS does not cover |
| NAT bytes unchanged, name resolves to public IPs | Custom DNS resolver doesn't forward AWS names to the VPC resolver |
| Private DNS option rejected or ineffective | VPC enableDnsSupport or enableDnsHostnames disabled |
| Connection timeouts to the service | Endpoint security group doesn't allow 443 from client subnets |
| Gateway endpoint ignored in one subnet | Subnet's route table isn't associated with the endpoint |
AccessDenied after cutover |
Endpoint policy or bucket policy too restrictive |
What are the alternatives to rerouting NAT traffic?
Endpoints are one lever among several, and some of the others remove bytes entirely instead of rerouting them.
Reduce bytes at the source. Pull-through caches for container images, a local package mirror, and layer reuse stop the same gigabytes from crossing the NAT on every deploy. Lowering log verbosity and batching API calls cut both NAT processing and the destination service's request charges.
Go fully private. Subnets with no route to a NAT, only endpoints, remove the per-GB fee and make egress explicit. Every new dependency then needs its own endpoint or proxy.
One NAT per AZ, local routing. If instances route to a NAT in another AZ, you pay cross-AZ transfer on top of processing. Per-AZ route tables fix this at the price of more hourly NAT charges.
Single NAT or none. This saves hourly cost but creates a single point of failure and reintroduces cross-AZ charges for every other AZ.
Centralized endpoints via Transit Gateway. This shares one set of interface endpoints across many VPCs. However, TGW attachment-hours and per-GB processing can cancel out the savings for high-volume traffic.
| Option | Ongoing cost effect | Engineering effort | Main risk |
|---|---|---|---|
| Gateway endpoints (S3, DynamoDB) | Removes NAT fees for that traffic, no endpoint charge | Low, one-time | Restrictive policies |
| Source reduction | Lowers all egress | Medium, ongoing | Stale caches |
| Fully private subnets | Removes NAT fees | High | Missing endpoints break calls |
| NAT per AZ | Removes cross-AZ fees, adds hourly cost | Low | Route table drift |
| Single or no NAT | Lower hourly cost | Low | Outage blast radius |
| Centralized via TGW | Varies, often offset by TGW fees | High, ongoing | Policy and DNS sprawl |
Gateway endpoints give the best return for the effort. Centralized designs and per-endpoint policies need maintenance every time a team adds a service, so count that engineering time as a cost in the comparison.
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 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.
- Changing a shared variable is one edit and one review instead of editing every service's
.envby hand.
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.
- A wrong or stale value is caught at review time by the services it affects, not by a failed deploy.
- 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.