ForHosting KIT · Home, food & hobbies

Cost per mile calculator

With fuel at 3.5 a gallon and a car that does 28 miles per gallon, each mile costs 0.125 in fuel. Enter the fuel price, your efficiency and, if you like, a per-mile maintenance figure to compare cars or set a mileage allowance. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Fuel price
3.5
Fuel efficiency
28
You get
Maintenance per mile
0
Fuel cost per mile
0.125
Cost per mile
0.125
Precision
6

This driving cost per mile calculator converts a fuel price and a vehicle's fuel efficiency into the cost of traveling one mile, then optionally adds a per-mile maintenance figure for oil, tires, brakes, and general wear. Drivers, fleet managers, and reimbursement desks use the same closed form to compare cars, set mileage allowances, and check whether a longer commute still beats other transport. The engine is pure finite arithmetic: fuel cost per mile equals fuel price divided by fuel efficiency, then maintenance per mile is added when supplied.

Where cost-per-mile thinking fits in commuting, fleets, and software

People meet cost-per-mile thinking when a household compares two used cars after a fuel-price spike, when a remote worker asks whether a longer commute still beats a rail pass, or when a small business sets a mileage reimbursement that should cover fuel plus a little wear without copying a published government rate blindly. Fleet desks use the same rate to rank vehicles by operating cost before they look at purchase price, and delivery contractors use it to quote a per-mile surcharge that stays honest when pump prices move.

Contest and homework practice often needs a fast, offline source of quotients so solutions can be checked without opaque spreadsheet macros under time pressure. Product and education tools use the rate when a learner types a pump price and an mpg figure and the UI must show a clean per-mile number next to a maintenance slider. This page is not a trip-fuel-cost estimator: it does not take distance and it does not return gallons needed for a journey.

Commute and car comparisons

Compare two vehicles by turning each car's mpg and today's pump price into a cost per mile, then adding a wear figure if you want more than fuel alone.

Mileage reimbursement worksheets

Build a transparent per-mile allowance from fuel price and efficiency instead of copying a published rate, and keep the same number in a classroom or payroll sheet.

What does the cost per mile calculator cost?

It is free in your browser on this page.

How is driving cost per mile defined?

Provide a non-negative fuel unit price, a strictly positive efficiency as distance per unit fuel, and an optional non-negative maintenance add-on.

What happens if fuel efficiency is zero?

Division by zero is undefined, so a zero or non-positive efficiency cannot produce a cost per mile.

Does this include insurance, tax, or depreciation?

No. It only divides the fuel price you supply by the efficiency you supply and adds optional per-mile maintenance. Adjust those inputs yourself if you want other factors in the rate.

Is efficiency miles per gallon or liters per 100 km?

Use distance per unit of fuel (miles per gallon, kilometers per liter, and similar). A consumption rate such as L/100km is the inverse shape and is not accepted as mpg.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/life/cost-per-mile

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/life/cost-per-mile \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"fuel_price":3.5,"fuel_efficiency":28}'
{
  "fuel_price": 3.5,
  "fuel_efficiency": 28
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "life.cost_per_mile",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_abs_value1000000000000000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Zero efficiency is rejected with invalid_input so clients never receive Infinity or NaN. Successful API calls cost $0.002 per item; failed validation is not charged.

What driving cost per mile means and what the response contains

Driving cost per mile is the money you spend to move a vehicle one mile, built from the pump price of fuel, the vehicle's distance-per-unit-fuel efficiency, and an optional add-on for maintenance that already lives on a per-mile basis. Adding eight hundredths of maintenance then yields twenty-four hundredths as the all-in operating rate. Fuel cost per mile is simply fuel price divided by fuel efficiency: if gasoline is four currency units per gallon and the car returns twenty-five miles per gallon, fuel alone is sixteen hundredths per mile. This calculator returns the normalized fuel_price, fuel_efficiency, and maintenance_per_mile you submitted, the intermediate fuel_cost_per_mile, the primary cost_per_mile result, a method tag fuel_over_efficiency_plus_maintenance, the formula string cost_per_mile equals fuel_price divided by fuel_efficiency plus maintenance_per_mile, and the precision used for rounding. There is no hidden tax, no currency conversion, no insurance or depreciation model, and no trip distance: the engine either divides two finite numbers, adds an optional non-negative maintenance term, and rounds, or it rejects the input with invalid_input. Rejected cases include missing fuel_price or fuel_efficiency, non-finite values, magnitudes above the documented ceiling, a negative fuel price, a negative maintenance figure, and any efficiency that is zero or non-positive, because division by zero is undefined and a non-positive miles-per-unit figure cannot produce a cost per mile. If you need a whole-trip fuel total, an electric charging estimate, or a flight fare per mile, use those dedicated tools; this page answers only the transparent driving rate with stable numeric output suitable for worksheets, reimbursement rules, and API consumers that must not invent extra costs.

How fuel price, efficiency, and maintenance are read

Efficiency must be expressed as distance per unit fuel, such as miles per gallon or kilometers per liter; a consumption rate such as liters per one hundred kilometers is the inverse shape and is not accepted as a substitute, because treating it as mpg would invert the rate silently. Optional leading plus signs and scientific notation on numeric strings are allowed when they parse as finite decimals; embedded spaces, hex prefixes, and non-numeric tokens are rejected with a clear message so a bad cell does not become a wrong cost-per-mile figure. The preferred fields are fuel_price for the unit price of fuel and fuel_efficiency for distance traveled per unit of fuel, but aliases price, gas_price, price_per_gallon, fuel_unit_price, and price_per_liter for the price, and efficiency, mpg, miles_per_gallon, fuel_economy, and economy for the efficiency, are accepted so spreadsheets, query strings, and typed forms can reuse the same contract. Optional maintenance_per_mile, with aliases maintenance, maint, wear, wear_per_mile, and maintenance_cost, defaults to zero when omitted so a fuel-only run stays a one-line division. Zero for fuel_price is valid and simply yields zero fuel cost per mile when efficiency is positive. Fuel efficiency must be strictly positive: if it is zero or at or below a tiny epsilon, the request fails with invalid_input because cost per mile equals fuel_price divided by fuel_efficiency is undefined when efficiency is zero. Negative fuel_price and negative maintenance_per_mile are also rejected so the model stays an operating-cost calculator rather than a signed ledger. An optional precision field, with aliases decimals and dp, chooses how many decimal places to expose, defaulting to six and capped at fifteen so JSON goldens stay stable.

Where cost-per-mile thinking fits in commuting, fleets, and software

Developers call the same contract from scripts to seed deterministic test vectors for mileage calculators, to normalize user-entered price and mpg before a comparison demo, or to satisfy product-challenge statements that demand a cost_per_mile field rather than a hand-waved trip total. Pair it with a trip-total tool when you already know how far you will drive and need a cash total for the tank, and keep this endpoint when the question is the unit rate itself. On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split — free interactive exploration and a priced, identical API — matches the rest of the KIT tier-A catalog and lets you move from a kitchen-table comparison to an automated pipeline without changing the mathematical result.

Fleet tools and test fixtures

Normalize fuel_price and mpg into a stable cost_per_mile field for ranking vehicles, quoting a surcharge, and asserting CI goldens without trip distance.

Read the full KIT documentation →