# How to calculate the energy payback of AI-optimised code

> Does the energy spent using AI to write or optimise code come back as run-time savings? The formula, published inputs, a worked example and a calculator.

Source: https://greenai.guide/engineering/energy-payback/  
Updated: 2026-11-26

## In short

An AI-assisted optimisation pays back when the energy saved per execution, multiplied by the number of executions over the code's life, exceeds the energy spent producing it: the model calls, the engineer's machine and the runs needed to test and prove the change. Because the investment is a one-off and the saving repeats, hot paths that run millions of times usually pay back quickly, while code that runs rarely almost never does. Estimate each term with stated assumptions and a range, measure the saving rather than assume it, and decide before you start.

## Key points

- Payback in executions is the energy invested divided by the energy saved per execution; payback in time divides that by the execution rate.
- Cheung and colleagues estimated that GPT-4-assisted development had on average 32.72 times the carbon footprint of manual development across 12 programming tasks, so the AI side of the ledger is not negligible.
- Published per-request figures span more than a hundredfold, from about 0.3 Wh for a typical short query to almost 40 Wh with a 100,000-token input (Epoch AI); use a range, not a point.
- In the worked example, a hot path called five million times a day pays back in about 1 to 40 days; the same effort on a script that runs once a day would take decades or longer.
- The saving is real only if it is measured and if freed capacity is switched off or reused; AI-generated code is not automatically more efficient.
- Carbon payback can differ from energy payback, because the AI work and the savings happen on different grids, at different times.

## What is the energy payback question?

**It asks whether the energy spent using AI to write or optimise code is repaid by the energy the code then saves
when it runs.** The AI work is spent once; the saving, if there is one, repeats on every execution. So the answer
depends mostly on how often the code runs and how long it stays in service.

The question matters because both sides are real. AI coding assistants have a measurable footprint: Cheung and
colleagues, comparing manual and GPT-4-assisted development on 12 programming tasks, estimated that the AI-assisted
approach had on average 32.72 times the carbon footprint of the manual one. At the same time, faster code on a busy
service saves energy every second it runs. Neither fact settles the matter alone. Doing the arithmetic does.

## What is the formula?

**Payback in executions is the energy invested divided by the energy saved per execution.** Write the terms out so
every assumption is visible.

The energy invested in the change is:

> E_invest = E_ai + E_dev + E_verify

- **E_ai**: the model calls made while writing, revising and debugging the change (requests × energy per request).
- **E_dev**: the engineer's machine while working on it (hours × device power).
- **E_verify**: the test, benchmark and CI runs needed to prove the change works and saves what it claims.

The saving per execution is:

> ΔE = e_before − e_after

measured in the same unit (joules per call, per request, per batch). Then:

> N_break-even = E_invest ÷ ΔE
>
> T_break-even = N_break-even ÷ executions per day
>
> Net saving over life = ΔE × N_life − E_invest

where N_life is the number of executions before the code is replaced or retired. If ΔE is zero or negative, the change
never pays back, however little the AI work cost.

Two versions of the question are worth separating:

1. **Is this optimisation worth doing at all?** Compare E_invest with the lifetime saving.
2. **Is AI the right way to do it?** Compare the investment with AI against the investment without it. The saving
   is the same if the result is the same, so only the difference in E_invest matters.

<!-- figure: a line chart of cumulative energy against time, starting below zero at the one-off investment and rising with a slope equal to the saving per day, crossing zero at the break-even point; a second, flatter line shows a low-traffic case that never crosses within the code's life. -->

## How do I estimate the energy of the AI assistance?

**Count the requests, multiply by a published energy-per-request estimate, and carry a range rather than a single
number.** Most providers do not publish per-request energy for coding tools, so every figure here is an estimate.

### Count the requests and their size

Your tool's usage logs or the provider's dashboard usually show the number of requests and the tokens in and out.
Size matters more than count: coding assistants send the open files, the conversation and tool output with each
request, and agent modes make many calls per task. Anthropic reported that, in its data, agents typically used about
four times more tokens than chat interactions, and multi-agent systems about fifteen times more.

### Choose energy-per-request figures

Published figures differ by boundary and by request size:

| Figure | Source | What it covers |
|---|---|---|
| 0.24 Wh per median Gemini Apps text prompt | Google, 2025 | Accelerators, host CPU and memory, idle machines and data-centre overhead |
| 0.10 Wh for the same prompt | Google, 2025 | Active AI accelerators only |
| About 0.3 Wh per typical GPT-4o query | Epoch AI, 2025 | An independent estimate, assuming about 500 output tokens |
| About 2.5 Wh with a 10,000-token input | Epoch AI, 2025 | Same method, long input |
| Almost 40 Wh with a 100,000-token input | Epoch AI, 2025 | Same method, very long input |
| 11 Wh per query (2.2 Wh inference plus 8.8 Wh share of training) | Cheung et al., 2025 | GPT-4; training energy spread over an estimated lifetime query count |

For coding work, the long-input rows are often closer to reality than the short-prompt ones, because each request
carries code and history. A sensible default is to compute three cases: low (about 0.3 Wh), central (about 2.5 Wh)
and high (about 40 Wh), and to say which you used. These are estimates for particular models at particular times;
Google, for example, reports that the energy of its median prompt fell 33-fold over one year, so older figures can be
far out for newer services.

**Training is a boundary choice.** Cheung and colleagues included a share of the model's training energy in each
query, which makes their per-query figure larger than inference alone. Either choice is defensible; state which you
made.

## How do I estimate the engineering and verification energy?

**Multiply the engineer's device time by its power, and add the energy of every run needed to prove the change.**
These terms are small for one laptop and can be large for heavy test suites.

- **The engineer's machine.** Cheung and colleagues used 4.075 W for a laptop while coding, the average of figures
  for two laptops. A desktop with monitors draws more; measure yours with a plug meter if it matters. Including the
  person's other energy use (lighting, heating, commuting) is a boundary decision: state it.
- **Verification.** Count CI runs, benchmark repetitions and load tests on the change. This can be larger than the
  AI term, as the worked example shows, but a saving you have not measured is not a saving; see
  [how to add energy-efficiency testing to CI/CD](/engineering/ci-energy-testing/).

### What the Cheung study does and does not say

Cheung and colleagues studied 12 tasks from three Codeforces contests, solved in Python, comparing manual
development (timed from contest submission data) with GPT-4-assisted development. Their headline is a mean ratio of
32.72 (standard deviation 8.41); the text gives a range of 19.92 to 43.81 times, although the lowest ratio in their
own results table is 19.66. Their boundary covers implementation, testing and debugging, excludes planning and design,
and their figures are estimates rather than meter readings. They found the gap grew with task difficulty.

That makes it a useful order-of-magnitude input for the second question (AI versus manual), not a constant. A smaller
model, shorter contexts or fewer requests would change it, and so would a task where AI saves many hours of a
person's time. See [using a coding assistant with a smaller footprint](/how-do-i/use-an-ai-coding-assistant-with-a-smaller-footprint/).

## How do I estimate the saving and the number of executions?

**Measure the saving per execution on the same machine, before and after, and take the execution count from
production metrics, not hope.** These two numbers usually decide the answer.

- **Measure ΔE.** Benchmark both versions with repeated, interleaved runs and compare medians, using hardware energy
  counters where you can. Report the unit (per request, per call, per batch) and the spread.
- **Check the saving is real in production.** A test-machine saving becomes a data-centre saving only if the freed
  capacity goes: fewer or smaller instances, or scale-down at quiet times. A server kept running at lower utilisation
  still draws power.
- **Count executions** from request logs, metrics or job histories, everywhere the code runs, including users'
  devices for client-side code.
- **Estimate the life** of the code from your own history of rewrites, and be conservative.
- **Do not assume AI code is efficient.** Cursaru and colleagues found that human implementations tended to be more
  energy efficient overall than code generated by Code Llama across C++, JavaScript and Python benchmarks (JavaScript
  was the exception), and that explicitly asking for energy-efficient code gave equal or worse results. ΔE can be
  negative. See [how to get AI to write energy-efficient code](/how-do-i/get-ai-to-write-energy-efficient-code/).

## A worked example

**A hot path pays back in days; the same effort on rarely run code never does.** The example combines published
figures with inputs that are clearly hypothetical. Replace the hypothetical ones with your own measurements.

### Inputs

| Input | Value | Status |
|---|---|---|
| Model requests in the AI-assisted session | 200 | Hypothetical |
| Energy per request: low, central, high | 0.3, 2.5 and 40 Wh | Published (Epoch AI estimates) |
| Engineer's laptop time | 4 hours at 4.075 W = 16.3 Wh | Hours hypothetical; power from Cheung et al. |
| Verification (CI and benchmark runs) | 200 Wh | Hypothetical (for example, two hours of a runner drawing 100 W) |
| Saving per execution, hot path | 0.15 J | Hypothetical, as if measured |
| Executions per day, hot path | 5,000,000 | Hypothetical |
| Life of the code | 3 years (1,095 days) | Hypothetical |

### Investment

- AI requests: 200 × 0.3 Wh = 60 Wh (low), 200 × 2.5 Wh = 500 Wh (central), 200 × 40 Wh = 8,000 Wh (high).
- Engineering and verification: 16.3 Wh + 200 Wh = 216.3 Wh.
- **Total E_invest: 276.3 Wh (low), 716.3 Wh (central), 8,216.3 Wh (high).**

### Hot path: an endpoint called five million times a day

The daily saving is 0.15 J × 5,000,000 = 750,000 J, or about 208 Wh a day. Over three years that is about 228 kWh.

| Case | E_invest | Break-even executions | Break-even time | Net saving over 3 years |
|---|---|---|---|---|
| Low | 276.3 Wh | about 6.6 million | about 1.3 days | about 227.8 kWh |
| Central | 716.3 Wh | about 17.2 million | about 3.4 days | about 227.4 kWh |
| High | 8,216.3 Wh | about 197 million | about 39 days | about 219.9 kWh |

Even in the high case the investment is under 4% of the lifetime saving. The uncertainty about the AI's energy
changes when the change pays back, not whether it does.

### Cold path: a script that runs once a day

Suppose the same effort goes into a daily report script and saves 40 J per run (hypothetical: for example, two seconds
less at 20 W). Over three years it saves 40 J × 1,095 = 43,800 J, about 12.2 Wh.

| Case | E_invest | Break-even time | Net over 3 years |
|---|---|---|---|
| Low | 276.3 Wh | about 68 years | about −264 Wh |
| Central | 716.3 Wh | about 177 years | about −704 Wh |
| High | 8,216.3 Wh | about 2,000 years | about −8,204 Wh |

The cold path never pays back within its life. Notice that verification alone (200 Wh) is more than sixteen times the
lifetime saving: even a hand-written change would not pay back in energy terms. Such a change may still be worth
making for speed, cost or clarity, but not as an energy saving.

### AI versus manual for the hot path

If the same optimisation took 12 hours by hand (hypothetical) with no model calls, its investment would be
12 × 4.075 Wh + 200 Wh = 248.9 Wh. Against the central AI case (716.3 Wh) the AI route costs about 467 Wh more, which
the hot path repays in a little over two days. The AI route is the right choice if it reaches the saving sooner or
finds a bigger one; it is the wrong choice if it produces a smaller or no saving.

<!-- figure: a log-log chart of break-even time against executions per day, with three bands for the low, central and high AI investment, a horizontal line at the code's expected life, and the hot-path and cold-path examples marked as points. -->

## How sensitive is the answer?

**Break-even scales with the investment and inversely with saving × traffic, so traffic and the measured saving
dominate.** A quick way to read the formula:

<!-- figure: a tornado chart showing how far the central break-even time moves when each input (executions per day, saving per execution, energy per request, number of requests, verification energy) is set to a low and a high value. -->

- **Ten times the traffic, a tenth of the break-even time.** Execution rate varies most between codebases.
- **Energy per request is the widest published range:** the low and high figures above differ by more than a
  hundredfold. For hot paths this hardly matters; for marginal cases it decides the answer.
- **Fixed costs bite at the low end.** Verification and engineering time do not shrink with the change, so small
  savings on cold code lose even when the AI work is cheap.
- **The life of the code matters.** Code replaced in six months gets a sixth of the savings of code that runs for
  three years.
- **Rework counts.** A change that fails review or is reverted adds its whole cost and removes the saving.

Low-traffic code rarely pays back; hot paths, shared libraries and code that runs on many users' devices often do.

## How does carbon payback differ from energy payback?

**Carbon payback weights each energy term by the carbon intensity of the grid where and when it was used, so it can
be shorter or longer than energy payback.** The Software Carbon Intensity specification expresses operational
emissions as energy multiplied by region-specific carbon intensity, plus embodied emissions, per functional unit, and
does not let market-based measures such as offsets or renewable certificates reduce the score.

- **Different grids.** The AI work runs in the provider's data centres, the laptop on an office or home grid and the
  saving on your servers or users' devices, each with its own carbon intensity.
- **Different times.** The investment happens now; the savings accrue over years, on grids that may be getting
  cleaner, which makes each saved kilowatt-hour worth less carbon.
- **Embodied carbon.** If the optimisation lets you run fewer or smaller machines, the avoided manufacturing
  emissions are a real saving, often the largest one; see
  [accounting for embodied carbon](/how-do-i/account-for-embodied-carbon-of-ai-hardware/).
- **Boundaries.** A provider figure that already includes data-centre overhead (Google's 0.24 Wh does) should not have
  PUE applied again.

With purely hypothetical intensities of 300 g CO2e/kWh for the AI work, 200 for the engineer and verification, and
100 for production, the central hot-path case above has an investment of about 193 g CO2e and a carbon break-even of
about 9 days, against 3.4 days for energy, because the savings happen on the cleanest grid. For real intensities, see
[how to find grid carbon intensity data](/how-do-i/find-grid-carbon-intensity-data/) and
[how to calculate an SCI score](/how-do-i/calculate-an-sci-score-for-an-ai-feature/).

## How do I decide before optimising?

**Estimate the ceiling on the saving before spending anything, and keep the AI work well under it.** The ceiling is
cheap to compute from data you already have.

1. **Profile first.** Find where the energy, or at least the CPU time, actually goes. Optimising code that is not on
   a hot path cannot pay back.
2. **Compute the ceiling.** Maximum lifetime saving ≈ current energy per execution × plausible fraction saved ×
   executions over the code's life. If even an optimistic fraction gives a ceiling near your fixed verification cost,
   stop.
3. **Set a budget for the session.** Cap requests or tokens in proportion to the ceiling; use a smaller model for
   routine edits and keep context to the relevant files.
4. **Measure, then merge.** Accept the change only if a repeated, interleaved benchmark shows a saving larger than the
   noise, with tests passing.
5. **Bank the saving.** Scale down capacity, lower the CI budget and record the before-and-after figures with the
   method, so the saving is real and can be reported honestly.

This is a form of the [efficiency and sufficiency](/articles/efficiency-is-not-sufficiency/) argument: the greenest
optimisation is sometimes not to optimise at all.

## A calculator you can adapt

**The function below computes the investment, break-even time and net lifetime saving, and optionally the carbon
equivalents.** It is an illustration to adapt; the example inputs are the hypothetical ones from the worked example,
except the energy per request (Epoch AI) and laptop power (Cheung and colleagues).

```javascript
// Energy (and optionally carbon) payback of an AI-assisted optimisation.
// An illustration to adapt. Energy in watt-hours (Wh) unless a name says otherwise.

const JOULES_PER_WH = 3600;

function payback({
  aiRequests,      // model calls made while writing and revising the change
  whPerRequest,    // energy per call, Wh (an estimate: record its source)
  devHours,        // engineer's device time on the change, hours
  devWatts,        // power of that device, W
  verifyWh,        // test and benchmark runs to prove the change, Wh
  savingJPerRun,   // measured saving per execution, joules (before minus after)
  runsPerDay,      // executions per day in production
  lifeDays,        // days the code will run before it is replaced
  grid = null,     // optional g CO2e per kWh: { ai, local, run }
}) {
  const aiWh = aiRequests * whPerRequest;
  const localWh = devHours * devWatts + verifyWh;
  const investWh = aiWh + localWh;
  const lifetimeSavingWh = (savingJPerRun * runsPerDay * lifeDays) / JOULES_PER_WH;
  const result = {
    investWh,
    lifetimeSavingWh,
    netWh: lifetimeSavingWh - investWh,
    breakEvenDays: savingJPerRun > 0 ? (investWh * JOULES_PER_WH) / savingJPerRun / runsPerDay : Infinity,
  };
  if (grid) {
    const investG = (aiWh * grid.ai + localWh * grid.local) / 1000;
    const savingGPerDay = (savingJPerRun * runsPerDay * grid.run) / JOULES_PER_WH / 1000;
    result.investG = investG;
    result.netG = savingGPerDay * lifeDays - investG;
    result.carbonBreakEvenDays = savingGPerDay > 0 ? investG / savingGPerDay : Infinity;
  }
  return result;
}

// Low, central and high cases that differ only in energy per AI request.
function paybackRange(inputs, whPerRequestCases) {
  return Object.fromEntries(
    Object.entries(whPerRequestCases).map(([name, wh]) => [name, payback({ ...inputs, whPerRequest: wh })]),
  );
}

// Example: hypothetical inputs, except Wh per request (Epoch AI) and laptop power (Cheung et al.).
const perRequest = { low: 0.3, central: 2.5, high: 40 };
const hotPath = {
  aiRequests: 200, devHours: 4, devWatts: 4.075, verifyWh: 200,
  savingJPerRun: 0.15, runsPerDay: 5_000_000, lifeDays: 3 * 365,
};
console.table(paybackRange(hotPath, perRequest));
console.table(paybackRange({ ...hotPath, savingJPerRun: 40, runsPerDay: 1 }, perRequest));
```

Run with Node.js, it prints the two tables in the worked example (break-even of about 1.3, 3.4 and 39.4 days for the
hot path). An interactive version would expose each input as a field, show the low, central and high cases side by
side, and label every default as published or hypothetical.

## What to do next

1. **Profile your service** and list the three hottest code paths by CPU time or energy, with executions per day.
2. **Compute the ceiling** on the lifetime saving for each before asking an assistant to optimise it.
3. **Log your assistant's requests and tokens** for the session, and pick a low, central and high energy per
   request with their sources.
4. **Measure the saving** with a repeated, interleaved benchmark, ideally in CI; see
   [energy-efficiency testing in CI/CD](/engineering/ci-energy-testing/).
5. **Bank it** by scaling down capacity, and record the method, boundary and figures; see
   [how to set a baseline for savings](/how-do-i/set-a-baseline-for-ai-energy-savings/) and
   [honest green claims](/practice/honest-green-claims/).
6. **Check the wider case** with [how to check an AI project is worth its footprint](/how-do-i/check-an-ai-project-is-worth-its-footprint/)
   and the [developers' guide](/guides/developers/).

## Frequently asked questions

### Does using AI to optimise code save energy overall?

Only if the code runs often enough. The AI work is a one-off cost, while the saving repeats on every execution. For code that runs millions of times a day the saving usually repays the AI work within days or weeks; for code that runs rarely it may never do so.

### How much energy does an AI coding session use?

Nobody publishes a standard figure. Multiply the number of model requests by an energy-per-request estimate. Published estimates range from about 0.3 Wh for a typical short query to almost 40 Wh for a request with a 100,000-token input, and coding assistants often send long contexts, so use a range.

### Is AI-assisted coding worse for the environment than writing code by hand?

On the tasks one study tested, yes: Cheung and colleagues estimated GPT-4-assisted development at about 33 times the carbon footprint of manual development. That is one study with one model and its own boundary. Whether it matters depends on what the code then saves or costs when it runs.

### How do I measure the saving per execution?

Benchmark the old and new versions on the same machine with repeated, interleaved runs and compare medians, ideally with hardware energy counters. A CI energy check does exactly this and gives you joules per run.

### Should I use energy or carbon for the payback?

Start with energy, which you can measure. Convert to carbon when you know where and when each part runs, because the AI work, your machines and your production servers may sit on grids with very different carbon intensity.

## Sources

- [Comparative analysis of carbon footprint in manual vs. LLM-assisted code development](https://arxiv.org/abs/2505.04521), Cheung, Kaul, Jahangirova, Mousavi and Zie, ResponsibleSE 2025 (arXiv 2505.04521) (2025)
- [How much energy does ChatGPT use?](https://epoch.ai/gradient-updates/how-much-energy-does-chatgpt-use), Epoch AI (2025)
- [Measuring the environmental impact of delivering AI at Google scale](https://arxiv.org/abs/2508.15734), Elsworth et al., Google (arXiv 2508.15734) (2025)
- [How we built our multi-agent research system](https://www.anthropic.com/engineering/multi-agent-research-system), Anthropic (2025)
- [A controlled experiment on the energy efficiency of the source code generated by Code Llama](https://arxiv.org/abs/2405.03616), Cursaru, Duits, Milligan, Ural, Rodriguez Sanchez, Stoico and Malavolta (arXiv 2405.03616) (2024)
- [Software Carbon Intensity (SCI) specification](https://sci.greensoftware.foundation/), Green Software Foundation (2024)
