Part of the reason for price discrepancies is that gas station owners set gas prices based on making a certain profit and deciding what the market will bear in that area. However, state governments tend to keep a watchful eye to determine whether customers are being unfairly gouged. The main reason gas prices vary so widely has more to do with the sheer number of regulations and restrictions placed on gasoline in the U.S. Gasoline prices do not fall under federal regulation; the prices fall under the state and sometimes even the municipality.
State and city regulators dictate to refiners and distributors their requirements, which sometimes vary depending on the season. For example, California has rules on production that make it difficult to bring in gasoline from neighboring states. When there are refinery or pipeline problems as there were recently, it can cause supply issues that can make gas prices soar.
Because of the state and local regulations, refiners can't produce just one blend of gasoline and instead have to produce dozens, keeping track of the complicated maze of which blend goes where. There's no record of the number of gasoline blends that refiners produce, but analysts have estimated that there are somewhere between 50 and 100 blends produced for sale in the U.S. Making multiple blends increases production costs and in turn can have a greater effect on prices where there are supply shortages in an area.
Then there are gas taxes. There is a federal gas tax as well as state taxes and sometimes taxes at the county or the municipality level. While the national average is 49.3 cents per gallon, gas taxes range from 26.4 cents per gallon in Alaska to 69.6 cents per gallon in New York. However, these figures are only averages for each state. Taxes on gasoline can vary widely within the state because of local taxes in much the way they vary at the national level due to state gas taxes.
So if you are unhappy with gas prices in your area, take a close look at the taxes and regulations on gasoline locally and contact your state and local officials if you want to see a change.