Investing is prone to manias and panics. Investors get excited as prices rise and become convinced they will continue to rise. People end up buying today what they should have bought years ago. The recent commodities sell-off reminded me of the rule I follow for commodities investing. Had you followed this one rule, you would have saved loads of money in 2008 and 2009 and made tons recently.

The rule
The time to own commodities is when they are down, when everybody has lost money in them, and when they trade below the cost of production.
 
-- Bill Miller

When a commodity is unprofitable for the companies that make it, high-cost producers die off or halt operations. The industry shrinks, leaving only the most efficient firms as high-cost producers gradually halt operations. This time is noted by large amounts of turmoil, falling stock prices, and occasionally bankruptcies before supplies decline and prices rise again.

Most importantly, it's the time to buy
That's easier said than done. It's gut-wrenchingly hard to buy when every day, anchors are ranting about how your stock is losing money, your friends are getting out of the market, and you feel nervous to invest. But that's how fortunes are made.

Consider Resource Capital Funds, the private equity firm that bought Molycorp (NYSE: MCP) from Chevron in September 2008 when rare earths had fallen off the highs of 2007 and early '08, making out like bandits.

Wilbur Ross bought the non-union assets of bankrupt Horizon Natural Resources to form International Coal Group (NYSE: ICO) in 2004 after the low prices of 2002 and 2003 caused many coal companies to struggle.

Where's the opportunity now?
Natural gas.

The commodity is currently trading at $4.25/mcf, below many companies' cost of production. Producers are slowly moving away from natural gas to other resources such as oil. For instance, SandRidge (NYSE: SD) bought Arena Resources last year for its oil reserves. Even natural gas heavyweight Chesapeake Energy (NYSE: CHK) is moving away from natural gas, aiming to drill for more oil and natural gas liquids, or NGLs, as opposed to straight natural gas. The reason is oil and NGLs can be drilled using the same technologies used to drill for natural gas; however, the profits realized by drilling for the former are much higher currently than can be realized for $4/mcf gas. This profit differential will continue to lead companies to shift production away from natural gas and toward oil. At current oil prices, the profit advantage of drilling for oil would still be there even if natural gas were at $6/mcf, leaving ample room for prices to rise above $6/mcf after enough companies have stopped producing it.

There will be more pain before there are large gains. Companies are still sitting on plenty of leases with obligations to drill or lose it, pushing down prices. The ones to own are the lowest cost producers, as they are best positioned to ride out the storm.

Below is a chart of some popular natural gas producers (and the industry average) ranked from highest to lowest production cost for the most recent quarter.

Company

Production Cost

Chesapeake Energy $6.78/mcfe
Range Resources (NYSE: RRC) $6.15/mcfe
Industry Average $5.41/mcfe
Southwestern Energy (NYSE: SWN) $3.85/mcfe
Ultra Petroleum (NYSE: UPL) $2.61/mcfe

Source: Company filings.

Both Southwestern Energy and Ultra Petroleum's production costs are below the current price of natural gas ($4.25/mcf). As you can see, though, Ultra Petroleum's costs are significantly below the rest of the pack.

What's to like about Ultra?
Despite having petroleum in its name, 90% of Ultra's revenue comes from natural gas. The first half of the company's name provides a fitting description of its management. The company has a returns-obsessed management team with CEO Michael Watford saying Ultra wants to "make money first and .... grow second." The team's incentives back up that statement; cash bonuses are based on cash flow, net income, and three-year production growth, while stock awards are based on return on equity, reserve replacement, and production growth.

As you would expect, the company has been doing well even with low natural gas prices. In its most recent quarter, the company had a net income of $70 million -- at a time when other natural gas producers have been reporting losses.

Foolish bottom line
When looking to invest in a commodity, you are best off investing in the lowest cost producer. Focus on commodities trading below the cost of production, and over time you should be duly rewarded. Looking for more ideas? Check out The Motley Fool's free report "The Only Energy Stock You'll Ever Need." Just click here to grab a copy.