The S&P 500 appears to be on its way to finishing the year down 20%. Many, if not most, investors, have seen their portfolios sink as well in 2022 -- but not Warren Buffett.

Most of Buffett's personal fortune is invested in Berkshire Hathaway (BRK.A -0.16%) (BRK.B -0.35%). Although there are still a few days left in December, Berkshire looks to be in great shape to deliver a positive, albeit small, annual gain. In such a dismal year for the overall stock market, Berkshire's performance looks fantastic.

What's the secret to this success? These six stocks are why Buffett beat the market in 2022.

Fueling a gain

If you look at a list of the top stocks in the S&P 500 this year, the energy sector will be well represented. Not surprisingly, a couple of oil stocks helped boost Berkshire's returns this year.

1. Chevron

Chevron (CVX -1.86%) makes up 9.3% of Buffett's portfolio, making it Berkshire's third-largest holding. Buffett has added to the position in Chevron throughout the year. And it's paid off handsomely: The stock is up close to 50% in 2022.

2. Occidental Petroleum

There's another oil stock that Buffett has bought even more aggressively this year. Berkshire now owns 21.4% of Occidental Petroleum (OXY 0.27%). That stake could get much greater. In August 2022, Berkshire secured regulatory approval to acquire up to 50% of Occidental. The stock ranks as Buffett's biggest winner this year, with a gain of nearly 120%.

Long-time favorites

Buffett hasn't always been as enthusiastic about oil stocks. However, he's been a fan of consumer staples stocks for decades. Two of the legendary investor's longtime consumer staple favorites have performed well in 2022.

3. Coca-Cola

Coca-Cola (KO -0.82%) is the fourth-largest holding for Berkshire, making up 8% of the total portfolio. Buffett loves the company's products, stating several years ago that he drinks at least five cans of Cherry Coke or Diet Coke each day. He's had a lot to like about the stock this year, as well. Coca-Cola's shares have jumped 7% while the overall market has tanked.

4. Kraft Heinz

Berkshire Hathaway owns 26.6% of Kraft Heinz (KHC -0.90%). That's such a lofty level that the food and beverage company is listed among Berkshire's subsidiaries on its website. Kraft Heinz ranks as the seventh-largest position in the conglomerate's portfolio, though, behind other companies that aren't viewed as de facto subsidiaries. It's delivered a solid 12% gain for Berkshire in 2022.

Playing games

Buffett is known to regularly play bridge, often with his pal Bill Gates, co-founder of Microsoft. The Oracle of Omaha has never expressed a desire to play video games, but he's no doubt highly interested in one video game maker.

5. Activision Blizzard

Berkshire initiated a position in Activision Blizzard (ATVI) before Microsoft announced plans to acquire the company. It's now the 10th-largest position in Berkshire's portfolio. The move to buy Activision shares has paid off very well. The stock is up close to 14% this year and could go higher if the Microsoft deal isn't derailed.

The one we can't leave out

The five stocks listed above aren't the only ones that Buffett owns that have delivered positive returns this year. However, the others make up less than 1% of Berkshire's portfolio. As such, they didn't contribute nearly as much to Buffett beating the market in 2022. There's one stock that we definitely can't leave out, though, that isn't one of Berkshire's equity positions.

6. Berkshire Hathaway

This stock is Berkshire Hathaway itself. Chevron, Occidental, Coca-Cola, Kraft Heinz, and Activision Blizzard definitely helped Buffett keep up his market-beating ways this year. But Berkshire's core businesses played an important role in this success as well.

Buffett refers to Berkshire's primary businesses as its "giants." These include the company's insurance operations, its BNSF railroad, and Berkshire Hathaway Energy. (Apple is the one "giant" where Berkshire isn't the majority owner.) These units continued to perform well in 2022 with solid revenue gains reported in the first three quarters of the year.  

The best-performing stocks for Buffett in 2023 could be quite different from the ones on the list in 2022. However, if Berkshire's core businesses chug along in the new year, there's a pretty good chance that Buffett will once again beat the market.