Gas cost can be calculated using the miles per gallon and fuel cost at stations along the road, should a refuel be necessary in the middle of the trip, using the mileage as a basis. Websites like FuelEconomy.gov help with calculating this cost without any lengthy research.
Mileage is simply the distance between two points as measured in miles. If a vehicle's fuel efficiency is calculated alongside the mileage between two cities, it is possible to know when refuels will be necessary and how much it will cost to refuel at a given location. Each trip has a high likelihood of having a different cost than the last, due to the range of variables that go into fuel costs.
It is always necessary to use the miles per gallon of a given vehicle to get an accurate estimation of fuel costs, as each vehicle can vary in fuel cost due to age, model and parts that vary from the factory model. Once this is accounted for, a state's average fuel prices must be added into the equation, if a vehicle needs to stop at a station during a long trip. These prices vary from state to state and city to city, and can even be different in stations a couple of minutes from each other. Due to this variance, only a rough estimate can be made of overall fuel costs.