The free market works because it allows people to decide for themselves what they value. Suppose I buy a loaf of bread from the baker for $2. I make the decision that the loaf is worth $2 -- or more -- to me. Otherwise, I wouldn't buy it. No one tells me what I like, want or need, nor what bread is worth or should cost. Similarly, the baker decides that it is worth it to him to sell his bread at $2 per loaf. He probably takes into account his rent, the cost of flour, labor costs and many other factors, but in the end both he and I conclude that the transaction makes sense -- otherwise there is no deal.
The baker decides how much bread to bake, and how much to offer for flour, based on what we are willing to pay for his bread. The combined effect of everyone's willingness to pay for goods and services sets prices and allocates resources across the entire economy. It is a bottom-up method, which allows everyone to make their own decisions, but it results in the most efficient allocation of resources and the greatest good for the greatest number.
While this may sound like some new search method instituted by Google, it is in fact old news, famously summarized in 1776 by a Scot named Adam Smith, in The Wealth of Nations. Smith was born in Kirkcaldy, Fife, about 25 miles from where I studied at St. Andrews.
But, like any theory, the "invisible hand" of the free market only works its magic under certain specified conditions. This, too, is old news, dating back a couple of centuries and taught without controversy in every Econ 1 class across the nation and indeed around the world.
The most important exception, for the purposes of this post, is something economists call "externalities," i.e., the impact of my buying decisions on other people. There are few, if any, externalities related to my purchase of bread. I buy the bread, I make toast, I have breakfast -- end of story. I pay the $2 price; you pay nothing and my decision to eat bread does not change your life.
But let's say I decide to pay my gardener to remove the leaves from my driveway, using a leaf blower. I pay $50, and I put up with the infernal racket those leaf blowers make. It is worth it to me to get the leaves out of my yard. Unlike my purchase of bread, however, my decision has consequences for ten of my neighbors. They, too, must put up with the outrageous sound made by that leaf blower, but their concerns are not mine and do not play a role in my buying decision. This externality blows away more than just leaves, it blows away the entire theory of the free market. The free market's "invisible hand" no longer works.
As I said, this is not advanced economics, far from it. It has been known since 1776, if not before, and is not in the least controversial. You cannot find an economist who would not agree with this analysis, although you could no doubt find many who could explain it more eloquently!
Let's apply the concept of externalities to gasoline. Burning gasoline dirties the air, air which we all breath. If you burn a gallon of gas, the impact on you is small. But, the combined impact on the millions (or billions) of people who breath the air is millions (or billions) of times greater. You also raise the temperature of the entire planet, however slightly. This may not matter to you, but multiply your decision by the 6,000,000,000 people who must live with it, and the math changes significantly. And, your decision to buy gas also drives our foreign policy. Your decision to buy a gas-guzzler impacts the entire world, not just you.
If it were just you and your one gallon of gas, it wouldn't make any meaningful difference. But the situation is different when we all buy gasoline. Billions of us make the same decision to burn a gallon of gas; each of us worries only about the gallon we are burning because, after all, that is all we can control with our buying decision. The result is a market that is massively out of whack.
There is a way to adjust for this imperfection in the free market: impose a tax on the consumption of gasoline. The tax must be high enough to balance the harm caused to others by your decision to burn a gallon of gasoline. Ideally, the money would go to eleviate the impact, i.e., to clean the air or to combat global climat change, but even if the money just goes into the general tax fund, it still serves the purpose of keeping the free market in balance.
But our government actually subsidizes oil production. If you believe in the free market, that decision makes no sense. Burning oil does not benefit others; it harms others. The government should not subsidize oil, it should tax it heavily, enough to compensate for the harm done by the consumption of oil.