It doesn't cost big oil companies anywhere near $90 to produce a barrel of crude. But they buy more crude than they pump, so the rising cost of a barrel cuts both ways.

NEW YORK (CNNMoney.com) -- Oil is selling for nearly $100 a barrel. Gasoline is near $3 a gallon. Oil companies are swimming in cash. But these record-high prices are both a boom and a burden for Big Oil.

Big oil companies refine more crude than they produce. That means they must buy crude to refine at market prices, which are now at record highs. Gasoline prices, meanwhile, have only made modest gains.

To be sure, producing the stuff has made big money for big oil over the last few years. Although it costs a lot less than $90 a barrel to pump, it's still not as cheap as you'd think.

The world's cheapest oil to extract comes from Saudi Arabia and costs $2 a barrel. But that oil, over 8 million barrels a day, is pumped mostly by the Saudi national oil company and is largely off-limits to Western oil firms.

For Western firms, it can cost as little as $5 to $7 a barrel to pump the most easily accessible oil from places like Venezuela or Azerbaijan, said FadelGheit, a senior energy analyst at Oppenheimer.

The costs don't stop there. On top of the $5-$7 production costs, there's also the the money it took to build the pumping facility. At several billion dollars a pop, capital costs typically add another $5 to $7 a barrel.

And that's the cost of producing oil in the cheapest regions of the world. Factor in expensive fields like the deep water Gulf of Mexico, the tar sands of Canada or water-laden output of Texas, and the average production and capital cost is somewhere in the low teens to mid $20s, said Gheit.

Still not bad, considering the selling price.

Enter government.

Gheit said taxes and royalty payments can range from 40 percent of profits in places like the United States to 90 percent or more in places like Russia or Libya.

"It's a very complex equation," he said of trying to figure out just how much it costs oil companies to produce oil.

A lot more. Exxon refined 5.6 million barrels a day in the third quarter 2007, but only pumped 2.5 million barrels a day. Chevron sold 3.5 million barrels a day of refined products but only pumped 1.7 million barrels of oil. Conoco refined 3.1 million barrels but pumped just 774,000.

These companies don't get a deal on the extra oil they must buy to refine, analysts said.

"Generally speaking, they have to pay fair market," said PeterTertzakian, chief energy economist at ARC Financial, a Calgary-based private equity firm. "If the refineries need it, they have to buy it."

Furthermore, Tertzakian said, accounting rules prevent the production side of a big oil company from giving the refining side a deal on crude. Other rules prevent the movement of crude from one country to another at below-market rates - rules largely designed so oil companies can't skimp on their tax obligations.

"They are subject to market forces, they pay like everybody else," said Gheit.

That's party why oil companies saw profits decline so much last quarter, when crude oil costs rose but gasoline failed to keep up.

Crude oil prices went from about $71 a barrel at the start of the quarter to more than $81 a barrel at the end. Gasoline prices, meanwhile, fell to a national average of $2.81 a gallon from $2.95, according to numbers from the Energy Information Administration.

As a result, Exxon reported at 10 percent drop in profits compared to the same time last year, while Chevron fell 26 percent and Conoco lost 5 percent.

Of course, with Exxon walking away with over $9 billion in profit for the last three months, it is unlikely anyone will lose sleep over how much the company must pay for oil.