Skip to content
Sandeep Kumar
Updated 5 min read

Why your AWS bill jumped: the NAT gateway trap

A NAT gateway bills per hour and per GB, and private subnets route almost everything through it. How to spot the charge and fix it with VPC endpoints.

Sandeep Kumar, Full-stack EngineerSandeep KumarFull-stack Engineer
On this page
  1. The charge nobody budgets for
  2. The traffic you did not know you had
  3. Where to look, because it is not called NAT
  4. The fixes, in order of return
  5. Ten minutes of prevention
  6. What I would change first

AWS bills rarely jump because of the thing you were watching. They jump because of a component that was doing its job quietly, in a line item named after something other than the service you think you are running.

The NAT gateway is the most common one, and the arithmetic surprises people because it charges in two directions at once.

The charge nobody budgets for

A NAT gateway lets instances in a private subnet make outbound connections without being reachable from the internet. Install packages, pull container images, call third-party APIs. Sensible architecture, and most reference diagrams include one.

The billing has three layers. There is an hourly charge per gateway, which accrues whether or not any traffic passes through it. There is a per-gigabyte processing charge on everything that does. And internet egress is billed separately on top, when that traffic leaves AWS.

At the time of writing, AWS's VPC pricing page puts the first two at roughly $0.045 per hour and $0.045 per GB processed in us-east-1, with internet egress around $0.09 per GB at first-tier rates. So a single gigabyte can be billed at about $0.135 on its way out, processing plus egress, and the gateway costs roughly $33 a month before carrying a single byte.

Check that page for your own region rather than trusting the numbers here, because they differ by region and they move. The structure is the part worth remembering: an hourly charge you cannot avoid, plus a per-GB charge that scales with traffic you may not realise is flowing.

The traffic you did not know you had

Once workloads sit in private subnets, a surprising amount routes through NAT by default. Package installs on every deploy and every container build. Image pulls, which are large and frequent. Telemetry, log shipping and metric agents, continuously. And calls to AWS services that have a public endpoint, which includes S3.

That S3 line is the expensive one. S3 is reached over its public endpoint by default, so a workload reading or writing objects from a private subnet sends all of it through the NAT gateway and pays processing on every gigabyte, in order to reach a service sitting inside AWS.

One engineering team documented what that looks like when it goes wrong: an S3 sync routed through NAT by mistake, 20,167 GB of NAT data transfer in a single day, billed at $907.53. Cost Anomaly Detection caught it within days, and the fix was one missing VPC endpoint. AWS refunded that particular bill after an explanation, which is worth reading as one team's experience rather than a policy you can plan around.

What makes this failure mode nasty is that nothing is broken. The application works. The architecture matches the diagram. The only symptom is a number on an invoice at the end of the month.

Where to look, because it is not called NAT

Cost Explorer has the answer and files it somewhere unhelpful.

Filter Service to EC2 - Other, group by Usage type, and look for NatGateway-Bytes for processing and DataTransfer-Out for egress. Nothing appears under a service called NAT, which is most of why this goes unnoticed.

If the processing volume looks implausible for your traffic, turn on VPC flow logs for those subnets and aggregate by destination. That gets you from a number to a cause. "NAT is expensive" is not actionable; "the nightly export is pushing 600 GB to S3 through NAT" is a ticket.

The fixes, in order of return

Gateway endpoints for S3 and DynamoDB come first by a wide margin. They route traffic to those two services inside the AWS network, bypassing NAT entirely, and they carry no hourly or per-GB charge at all. For most workloads this is the single biggest reduction available, and it is an endpoint plus a route table entry:

hcl
resource "aws_vpc_endpoint" "s3" {
  vpc_id            = aws_vpc.main.id
  service_name      = "com.amazonaws.${var.region}.s3"
  vpc_endpoint_type = "Gateway"
  route_table_ids   = [aws_route_table.private.id]
}

Interface endpoints cover the rest. ECR, Secrets Manager, CloudWatch Logs and others support PrivateLink. These do carry an hourly and per-GB cost, so they are not free, but the per-GB rate undercuts NAT processing and for something like container image pulls they pay back quickly. Add them where the volume justifies it rather than reflexively, or you will have traded one fixed cost for several.

Then count your gateways. One per availability zone is the resilient pattern and it multiplies the hourly charge by the number of AZs. In non-production environments, one is usually enough, and nobody is going to page you about it.

Release idle public IPv4 addresses while you are in there. Public IPv4 is now billed at roughly $0.005 per hour whether attached or idle, about $44 a year each, and forgotten addresses from old experiments are pure waste.

And it is worth asking whether you need NAT at all. It exists to give private subnets outbound access. A small application in a public subnet with tight security groups, or one whose outbound needs are entirely covered by VPC endpoints, may not need one. Reach for the private-subnet pattern because the workload warrants it, not because the diagram had it.

Ten minutes of prevention

Cost Anomaly Detection, configured before you need it rather than after. It is what caught the incident above within days instead of at the end of the month, and it is the highest-value thing on this page.

A budget alert at a threshold you would genuinely want to be woken for, which is a different number from the one you would like the bill to be.

And a five-minute read of Cost Explorer grouped by usage type, once a month. Not a review meeting. A scan for line items larger than your mental model of the system.

Payload size is the other half of this. Traffic you do not send is traffic you are not billed for, which is why compressing a cache from 14 GiB to 1.6 GiB pays twice, in memory and in transfer.

What I would change first

The NAT gateway is not expensive because AWS priced it badly. It is expensive because it sits in the default path of traffic that has no business going through it, mostly S3, and bills hourly and per gigabyte at the same time.

Add the gateway endpoints for S3 and DynamoDB, confirm in Cost Explorer that NatGateway-Bytes actually dropped, and turn on anomaly detection so the next surprise arrives as an alert rather than an invoice. The first two take an afternoon. The third takes ten minutes and is the one that catches the thing you have not thought of.

Frequently asked

Why is my AWS NAT gateway so expensive?

Because it charges twice. There is an hourly charge for each gateway that runs whether or not traffic flows, plus a per-gigabyte processing charge on everything passing through. Internet egress is then billed separately on top, so a single gigabyte leaving a private subnet can be billed by both the NAT gateway and data transfer out.

How do I reduce NAT gateway costs?

Route the traffic around it. A gateway VPC endpoint for S3 and DynamoDB keeps that traffic inside the AWS network and carries no hourly or per-GB charge, which usually removes the largest share. Interface endpoints cover other services at a lower rate than NAT processing. Consolidate to fewer gateways where availability requirements allow, and release unused public IPv4 addresses, which are now billed hourly whether attached or idle.

How do I find what is driving NAT gateway charges?

In Cost Explorer, filter the service to EC2 - Other and group by usage type. Line items containing NatGateway-Bytes show processing volume, and DataTransfer-Out shows egress. VPC flow logs identify which instances and destinations are responsible once you know the volume is real.

Do I need a NAT gateway at all?

Not always. A NAT gateway exists so instances in a private subnet can reach the internet outbound. A small application whose instances sit in a public subnet with tight security groups, or one whose outbound needs are covered by VPC endpoints, may not need one. Assume you need it only when the architecture genuinely requires private subnets with outbound access.

Found this useful?Share on XShare on LinkedIn

Related reading