Oil prices have risen 58% since late March and are now trading at all-time record highs well above $90 a barrel.

Still, over this period, nearly every major oil and gas company saw their income results deteriorate. What gives?

The answer is simple. Like any business, profits in the oil and gas business aren't determined by the industry's cost of inputs. Rather, profits for oil companies are determined by the spread between their cost of goods sold and the price of their finished products. The greater the spread, the more the companies profit.

For oil companies like

Exxon Mobil

(XOM) - Get Report

,

Chevron

(CVX) - Get Report

,

ConocoPhillips

(COP) - Get Report

,

British Petroleum

(BP) - Get Report

and

Royal Dutch Shell

(RDS.A)

, the product that they sell is not crude oil.

Rather, they sell products made from crude oil like motor gasoline, jet fuel and chemicals.

Most oil companies drill for oil themselves. After refining and marketing that oil, profits are calculated by subtracting the costs of finding and developing the oil from the final price that the company earns from selling the product.

Finding and development costs range widely depending on location, technical difficulty of extraction, taxation and subsidies. These expenses are about $2 a barrel in Saudi Arabia and reach as high as $40 a barrel in the oil sands of Alberta, Canada.

However, most companies don't produce enough oil to cover the demand for the refined products that they make. Thus, oil companies must buy additional crude from the global market in order to fill that void. The remainder mostly comes from the major producing countries like Saudi Arabia, Russia, Canada and Iran.

In the first quarter of 2007, the average price that oil companies had to pay to buy crude from the marketplace was around $58 a barrel. In the third quarter, this number was closer to $75 a barrel. In this situation, the sales price of refined products must keep up with the rising price of crude oil if profit margins are to hold steady.

Unfortunately for the integrateds, this didn't happen this year. In fact, the nationwide spot price for reformulated gasoline, which is the most important product that oil companies refine, actually fell in price from about $2.27 a gallon in the first quarter to around $2.10 a gallon in the third quarter.

That means that between the first quarter and the third quarter, the profit earned on a barrel of gasoline fell from around $37 to about $13.

Hence the discrepancy between this year's first quarter and third quarter operating results from the major oil and gas companies. Back in the first quarter, Exxon, Chevron and ConocoPhillips all posted strong earnings with excellent growth over the same period the previous year. However, each of these companies reported declines in the most recent quarter, all because of lower refining margins.

The lesson to be learned here is that oil prices don't determine what kind of profits are earned by major integrated oil companies. This can appear counterintuitive if you pay attention to the mass-media or to jawboning by thick-skulled politicians.

At the first hint of rising oil prices, those who don't do their homework begin to whine about price-gouging and the need for windfall profits taxes.

Investors in energy should remember the facts. As oil prices test $100 a barrel, don't assume that oil companies are reaping huge rewards. Instead, run a quick calculation of the crack spread for gasoline and distillates. If those spreads are rising, energy investments will appreciate. If the spreads are falling, be prepared for surprise earnings misses in the next round of conference calls.