This question is a frequent source of confusion.I remember a post by Tesla Motors (not sure where, probably Facebook) when they say that the electricity to transport and refine one gallon of oil to produce gasoline is as much or even more than the Model S needs to drive the same miles as you could with that gallon of gasoline. It's really important to factor in all the pollution and cost and side effects of gasoline when comparing it to electricity.
Edit: found some good info on how much energy is used to refine oil here
The correct answer is that 5-7 kWh of energy, not electricity, is used to refine a gallon of gasoline. Only about 4-5% of that energy is in the form of grid electricity so therefore about 0.25 kWh of electricity is used to refine one gallon of gasoline. If you were careful you could drive about a mile on that in your Model S. The vast majority is from fossil fuels -- either natural gas or leftover unpopular (unsaleable) distillates from previous refinery output. Most of that energy wouldn't exist if you weren't already refining oil in the first place. All of the fossil energy used in refining would have to be run through an electric power plant before it could be used to power an electric car.
You can find all the details you ever wanted to know including the basic calculations and the breakdown on the different energy input types used in refining and why the recent FullyCharged episode "volts for oil" is wildly misleading here:
A petition to Toyota to build electric vehicles | Page 12 | PriusChat