The value of long-term investing became quite evident over the past 12 months, with the stock market in bear market territory for most of that time. Those investing for the long term have the ability to ride out dips like this and benefit from the fact that bull markets typically last longer than bear markets.

There are two stocks in particular that offer solid proof of this thesis over the past 10 years -- Mastercard (MA -0.63%) and S&P Global (SPGI -1.21%). Let's take a closer look at why these two hot stocks remain great buy-and-hold candidates that you'll want to keep positions in until you retire.

Two stocks with a history of huge returns

This has been a brutal stock market -- the worst since the Great Recession in 2007-09. But even in this market, both Mastercard and S&P Global have generated stellar long-term returns.

Payment facilitator Mastercard, which went public on May 25, 2006, saw its stock post an average annual return of 22.4% over the past 10 years (as of Nov. 14). Since its initial public offering (IPO), the annual return is an even better 30.3%. That return factors in the Great Recession, the 2020 pandemic crash, and the current bear market. This year, while the Nasdaq Composite is down some 28.6% and the S&P 500 is down 17.4%, Mastercard is only down about 5.3%.

MA Chart

MA data by YCharts

S&P Global, known for its credit rating business, analytics, and indexes, has been almost as strong. Over the past 10 years, it has posted an annualized return of 21.5%. Prior to 2016, it was known as McGraw-Hill Companies, and that company dates back to the early 1900s. But if you just went back 20 years, the stock has returned 12.8% on an annualized basis, which beats the 7.7% annualized return by its own S&P 500 over that same span.

While both companies are vastly different, there is one common thread as to why they have -- and should -- continue to perform so well.

Visa is protected by moats

While these are great companies for a lot of reasons, the one common thread between the two is the competitive advantage they have in their respective industries. This type of advantage -- which is extremely difficult for competitors to crack -- is sometimes called an economic moat for the fact that its advantage is so well protected.

This has been particularly true for Mastercard, as it and Visa have long enjoyed a duopoly in the credit-processing space with their two massive networks. While there are other credit processors, namely Discover Financial and American Express, they operate on their own networks and act as banks too, lending the money as credit to their customers. Mastercard and Visa are not banks, but they essentially own the networks on which pretty much all payments are processed.

This advantage is being challenged for the first time by legislation in Congress -- the Credit Card Competition Act -- which would require most banks to process electronic credit transactions on at least two affiliated networks -- and one of them can't be Visa or Mastercard. This bill has not passed, but lawmakers say it would create more competition and have the effect of driving down fees for consumers.

It remains to be seen if this will pass with the new Congress and what impact it will have long term if it does. While it could have an impact at the margins, Mastercard will still remain one of the dominant networks. Its low overhead, great efficiency, and high, 57% operating margin make it a great stock to own for the long term.

S&P Global's superpower

S&P Global also enjoys a moat in a couple of different areas. It is the largest credit-ratings agency in the country, along with Moody's, both of which own about 40% of the market. One smaller competitor, Fitch Ratings, owns about 15% of the market, but there really are no other competitors, and there likely won't be as there can only be a few; otherwise, the ratings will be watered down.

The other superpower that S&P Global has is its diversity of revenue and reliable streams of income. It has six different business lines: credit ratings, indexing (where it is also a market leader with a moat), market intelligence, commodity insights, engineering solutions, and S&P Mobility.

These units balance each other out well, so when one is down, another is up. For example, in the most recent quarter, credit ratings were down, but market intelligence and commodity insights were up big, as more clients sought data, analytics, and advisory services in a down market. On top of that, most of its income is generated through fees and subscriptions, which provide steady, reliable revenue that produces lots of cash flow and high margins. And with 49 straight years of dividend increases, it is on the precipice of becoming a Dividend King

Sturdy investments for years to come

The advantages for these two stocks are so strong, their business models are so sturdy, and they are so efficient, they are both great candidates to continue to weather the market's ups and down and post excellent returns over the long term.