For a combustible mixture to ignite, it must be within its flammability limits. This forum provides an anecdotal explanation for gasoline's inflammability in an automobile tank:
...when the tank is empty the vapor level is above the HEL or UEL (upper explosive limit). If the flammable vapors are higher in concentration than this level it will not ignite. We used to weld inside the diesel tanks in the Navy because it was above the UEL and therefore was safe for hot work.
This anecdote is correct: Chemical engineers are careful to use the physical and chemical properties of flammable liquids to ensure their safe storage. However, can we be certain that gasoline will always be safe in your gas tank?
The answer is yes – unless you're driving under very, very specific conditions. To be within gasoline's flammability limits, you would need a very low fill level (to allow enough headspace for proper gas mixing) and very low temperatures (around -20°C). I've included more information about an experimental investigation into these conditions below, but this should be enough to answer your question – if you're really worried about it, keep your tank more than ~1/8th full, and you'll be just fine.
The National Renewable Energy Laboratory (NREL) investigated gasoline flammability in a series of publications titled An Experimental and Modeling
Study of the Flammability of Fuel Tank Headspace Vapors from High Ethanol Content Fuels. The first volume concluded:
Gasoline is so volatile at most ambient temperatures that the headspace vapors in the tank are actually too rich to burn, as long as some liquid fuel remains. However, as temperature drops, or as the liquid fuel level goes down, the volatility of the fuel decreases. As liquid level drops, there is less fuel vapor mixed with the air in the tank.
If the ambient temperature is cold enough and the tank is nearly empty, then the fuel-air mixture in the tank becomes flammable and can pose an explosion hazard if ignited. Similarly, when refueling a nearly empty tank at very cold temperatures, the headspace vapors are expelled as a plume of fuel vapor and air as the liquid enters the tank, producing a flammable plume. An ignition source within that plume could lead to a flame traveling back down into the tank and causing an explosion. This has always been the case with gasoline, but the temperatures and fill levels needed to produce a hazard are rarely encountered, so fires and tank explosions are very unlikely, although not impossible.
After generating their model in volume one, NREL examined "field samples" (gasoline from common fill stations) in volume two:
...at least some of the ethanol fuels that are currently available when and where Class 3 conditions exist (-5ºC and below) are likely to produce flammable vapors within the ambient temperature range where they are used.
...results indicate that mid-level blends...are unlikely to significantly increase the risk of producing flammable vapors over that of the base gasoline used for the blends.
The vapor pressure data for the blends indicated that a reduction in ethanol content to about 65% would be needed to achieve the minimum vapor pressure specification. The flammability data trends suggest that blends with ethanol content in this region would provide a favorable trade-off between avoiding the formation of flammable vapors and maximizing the ethanol content of the fuel.
Comparisons of the flammability results of the field and laboratory samples indicate that
vapor pressure (DVPE) alone does not adequately predict the flammability of the fuel tank
vapors formed at low temperatures. The properties of the hydrocarbon portion of the fuel
must be considered as well.
Finally, volume three focused on in-depth experimental study:
The experimental results presented in this report are, to some extent, unique to the
apparatus and test conditions that were used for the experiments. Important factors that would
have affected the observed behavior included the use of a fill level of 5%, the use of a strong
spark for ignition, and the use of test chambers with a relatively small internal volume. Thus, the
combustion pressures and flammability limit temperatures presented in this report would be
expected to differ from those that might be encountered in other situations. For example, a higher
fill level or a weaker ignition source would lower the upper flammability limit temperature (the
headspace vapors would have to be colder to be flammable), while a larger headspace volume
would likely lead to higher maximum pressures and higher rates of pressure rise. Therefore, the
results presented in this report should be interpreted primarily as a relative indication of the
headspace vapor flammability of the test fuels. It should also be noted that results were obtained
with blends made from specific gasoline samples. The quantitative results at a given vapor
pressure level might not be exactly the same if different gasoline samples with different
hydrocarbon compositions were used.