After one of the worst years for the stock market in recent times, there is some optimism that 2023 will be a little or a lot better (depending on the source). But others contend that we're not out of the proverbial woods yet and that the market could have another correction this year, especially given the expectation for further economic slowdown.

As an investor, you want a portfolio that's built for the long term and one that can ride out short-term swings. This means you need a diversified portfolio of stocks that react differently in various market environments. Here are two stocks you might want to consider for your portfolio that have what it takes to hold up well if there is another crash.

1. Mastercard: A flight to quality

During times of market turbulence, you often hear about investors taking "a flight to quality." This means stock buyers focus more attention on large, established companies with big brands that are among the leaders in their markets. These companies are generally well-capitalized, have been through the market's ups and downs, and have the earnings power to weather any storms.

An example of a quality, all-weather blue chip company was seen in 2022 when turbulent markets pushed the S&P 500 down about 19.4% and the Nasdaq Composite fell about 33%. Over that same timeframe, credit card company Mastercard (MA -0.07%) only fell about 2%. So far in 2023, the stock is up around 8.4%.

Mastercard has been remarkably steady over the years, primarily because it maintains a duopoly in the credit processing space with Visa. These two firms control the bulk of the credit card and payment processing market because of their massive networks. The other big competing credit card companies all maintain their own closed-loop networks, meaning they are both lenders and issuers.

Mastercard does not lend to users -- that comes from third-party banks that issue the cards and partner with Mastercard. Mastercard generates its revenue from the small-percentage fees levied each time a card is used. It has a simple business model with low overhead that is effective in all market cycles. In fact, 2022 was Mastercard's first year since 2010 when the stock price ended the year down.

A recession would not be ideal for Mastercard as it would likely lead to lower consumer spending. But the company has been through recessions before, and because of its duopoly, its high margins, and the ongoing gradual shift to digital payments, it has shown the ability to navigate tough times. Over the past decade, the stock has produced 21.9% annual returns for its investors.

MA Chart

MA data by YCharts

2. Berkshire Hathaway: A bear necessity

Berkshire Hathaway (BRK.A -0.28%) (BRK.B -0.68%) is better known as the company Warren Buffett runs. For a lot of people, you don't need to say any more than that, as Buffett is considered one of the greatest investors of all time. And he has the track record to prove it. Since 2009, Berkshire Hathaway has only ended the year with a negative return twice -- and neither of those times were last year.

In 2022, when the markets were down big, Berkshire Hathaway was up about 3.3% for the year. The stock has a history of zigging when the market zags, like in 2016, when the S&P 500 was down 4% and Berkshire Hathaway was up 3%. Over time, the company Buffett and his team built has an average annual return of 12.2% over the past 10 years through Jan. 31, beating the S&P 500.

Berkshire Hathaway is the holding company for multiple businesses. The company is most well-known for its roughly $343 billion investment portfolio of approximately 40 stocks, which Buffett and his team have built up over the years. The three largest holdings, as of Sept. 30, were Apple, Bank of America, and Chevron.

The company also wholly owns or has a majority stake in about 65 companies across various industries, including well-known brands like Dairy Queen, GEICO, and Duracell. In addition, Berkshire Hathaway owns several insurance businesses (including specialty insurance), railroads, utilities, and energy companies.

While the stock portfolio was down this past year, given the bear market, it was buoyed by the performance of its privately held companies, particularly those in the insurance space. Buffett's rigorous investment strategy and discipline, and focus on value, have enabled the company to perform relatively well in all market cycles.

Money well invested

Berkshire Hathaway's A shares carry a high per-share price, but the stock is much more affordable if you buy the B shares, which are currently valued at about $310 per share. Mastercard is a little steeper at about $365 per share. But even if you only had $2,000 to invest in each, a handful of shares in each of these companies would be a good investment.

Both Mastercard and Berkshire Hathaway would give your portfolio some balance if the market endures another correction, and they are both excellent long-term stocks that have beaten the market over the long run.