Gas Cost Calculator Formula
Understand the math behind the gas cost calculator. Each variable explained with a worked example.
Formulas Used
Total Fuel Cost
total_fuel_cost = gallons_needed * gas_priceGallons Used
gallons_used = gallons_neededCost Per Mile
cost_per_mile = gas_price / mpgVariables
| Variable | Description | Default |
|---|---|---|
trip_miles | Trip Distance(miles) | 300 |
mpg | Vehicle MPG(MPG) | 28 |
gas_price | Gas Price Per Gallon(USD/gal) | 3.5 |
gallons_needed | Derived value= trip_miles / mpg | calculated |
How It Works
How to Calculate Gas Cost
Divide the trip distance by your MPG to find gallons needed, then multiply by the gas price.
Formula
Gallons = Distance / MPG
Fuel Cost = Gallons x Price Per Gallon
Worked Example
300-mile trip in a car getting 28 MPG with gas at $3.50/gallon.
trip_miles = 300mpg = 28gas_price = 3.5
- 01Gallons needed = 300 / 28 = 10.71 gal
- 02Fuel cost = 10.71 x $3.50 = $37.50
- 03Cost per mile = $3.50 / 28 = $0.125
Ready to run the numbers?
Open Gas Cost Calculator