One key benefit of holding commodity stocks is their ability to offset the inflation investors experience in their daily lives. For instance, energy stocks have been on a tear as the pandemic has receded and in the wake of Russia's invasion of Ukraine. So, holding those stocks in your portfolio would have helped offset the pain we're all feeling at the pump.

Another concern these days is food prices. In the wake of Russia's invasion, food prices are up 8.8% over the past year, even higher than the headline 8.5% inflation number reported last week, with "food at home" prices up 10% and "food away from home" prices up by 6.9%.

Looking to offset some of those costs in your portfolio? Here's why CF Industries (CF -0.33%) may be the ticket.

CF Industries is a fertilizer powerhouse

Russia's invasion of Ukraine is potentially even more problematic for food than it is for oil and gas. Not only do Russia and Ukraine supply nearly 30% of the world's wheat, but Russia is also the largest exporter of nitrogen fertilizer. So, if wheat supply and fertilizer supply are affected, that's a problem. Add in last year's drought in South America, which affected Brazilian crops, and it's not a great situation.

No wonder CF Industries had the most profitable year in its history in 2021 and is set to grow profits even more this year. CF Industries is a large U.S.-based supplier of ammonia and ammonia derivatives largely used in nitrogen fertilizer. Due to its scale and access to low-cost U.S. natural gas, CF has a huge advantage over ammonia producers elsewhere. With energy costs encompassing 40% of the production cost of ammonia, the advantage is hard to underestimate.

CF's investors should know this because CF also has smaller operations in the United Kingdom. In 2021, the contrast between the company's U.K. and U.S. operations couldn't have been starker. The price of natural gas in the U.S. averaged $3.82 per MMBtu in 2021. Meanwhile, the U.K. had an energy crisis, and natural gas prices shot up to an average of $15.50 per MMBtu!

Consequently, the U.S. segment delivered record results as the price for ammonia-based products soared. Meanwhile, CF had to shut down operations in the U.K. and then only reopened them with help from the U.K. government. Even then, CF operated the U.K. segment at a slight gross margin loss, and the company took $521 million in impairment and goodwill write-downs associated with the U.K. assets.

Still, the U.K. operations are a very small part of CF Industries' business, and the headwinds there didn't prevent the company from going on to generate record profits and cash flow last year. The average price for CF's products rose a whopping 74% in 2021, and free cash flow nearly tripled to $2.17 billion, up from $748 million in 2020.

With developed nations potentially shunning Russian nitrogen products and with higher energy prices limiting the ability of other countries to produce fertilizer profitably, CF finds itself in quite a fortunate position.

Tractor dusts crops with fertilizer in open field.

Image source: Getty Images.

Has the stock run too far, though?

Certainly, some might feel CF has run too far too fast. The stock is up more than 50% on the year, after all. Yet, CF also trades at 6.8 times this year's earnings estimates. That super-cheap PE ratio indicates investors are pricing in a reversion to the mean after this year. However, there is, unfortunately, a possibility food prices may remain stubbornly high.

On its fourth-quarter earnings release -- which, keep in mind, happened before Russia's invasion -- management was already projecting a strong year with tight supply and soaring demand. Grain stocks were low, and nitrogen supply was low at the beginning of 2022 to start with. That was because of high energy prices and weather-related incidents in the U.S. that had also taken supplies off-line.

Meanwhile, COVID-19 had delayed maintenance projects in 2020, and CF took a record amount of maintenance-related projects last year. Management anticipated it would take two full growing seasons for supply to catch up to demand. And to reiterate: This was before Russia's invasion.

So yes, one could be investing in CF Industries at the "top" of a cycle. But if energy and food shortages persist, it's quite possible CF could appreciate materially from here. And if you are constructing a portfolio, CF stock could act as a useful hedge against rising food prices in not only your life but also the rest of your portfolio.

Meanwhile, investors get paid a 1.1% dividend for holding this hedge, even at these all-time-high levels, and management also opportunistically repurchases stock. For those investors looking to combat the negative effects of high food inflation, CF Industries could play a useful role in a diversified portfolio today.