Warren Buffett is one of the most successful investors in history. His knack for picking great stocks has not only helped Berkshire Hathaway become one of the largest companies in the world, but it has also made him one of the wealthiest people on the planet. That success makes him an excellent source of inspiration.

Here are two stocks Buffett owns (through Berkshire or a subsidiary) to buy now and hold forever.

Microsoft: Digital transformation

Berkshire Hathaway does not have a stake in Microsoft (MSFT 1.82%), but its subsidiary New England Asset Management does, and Buffett ultimately owns those invested assets. The bull case for Microsoft is straightforward: The company provides mission-critical software for business productivity, collaboration, and cybersecurity, and it offers a broad range of cloud infrastructure and platform services (CIPS). Few companies, if any, can facilitate digital transformation on that scale.

Admittedly, Microsoft delivered a disappointing financial performance last quarter. Revenue rose just 2% to $52.7 billion, and adjusted earnings fell 6% to $2.32 per diluted share, but those results say more about the economy than they do about Microsoft.

Many businesses are cutting costs to compensate for inflation-fueled softness in consumer spending, and the strong dollar has led to unfavorable foreign exchange rates. Those headwinds will likely persist in the near term, but Microsoft is well positioned to reaccelerate growth when the economy eventually improves.

Research company Gartner says the company dominates the market for productivity suites. In fact, Microsoft 365 is the most popular enterprise application in any category, and that brand authority has helped the company position itself as a key player in other software verticals, including enterprise resource planning, communications, and several cybersecurity end markets. All three of these are expected to notch double-digit growth through the end of the decade.

Meanwhile, Microsoft is taking market share in cloud computing. Azure accounted for 23% of CIPS spending in the most recent quarter, up from 21% in the prior year. That puts the company firmly in second place behind Amazon Web Services.

But its expertise in developer tools, hybrid computing, and artificial intelligence (AI) -- including its partnership with OpenAI -- should continue to spur adoption. That bodes well for Microsoft. Grand View Research estimates that cloud-computing spending will increase by 14% annually through 2030.

Here's the bottom line: Buffett likes companies with durable competitive advantages, and Microsoft has those in spades. Its brand authority and strong presence across several high-growth markets portend better days ahead.

In fact, investors can reasonably expect Microsoft to grow revenue at a double-digit pace through the end of the decade. That makes its current price-to-sales (P/S) ratio of 10.6 look quite reasonable, and investors should feel comfortable buying this stock at its current price.

Mastercard: Digital payments

Mastercard (MA 0.07%) operates one of the largest card payment networks in the world. It accounted for 24% of card purchases in 2021, third behind Visa and China's UnionPay.

And its acceptance network spans 80 million merchant locations, which puts Mastercard in first place alongside Visa. That scale is a tremendous advantage. It obligates new merchants to accept Mastercard because consumers have come to expect it, and it also discourages potential challengers.

Payment processing is a very scalable business. Mastercard incurs virtually no expense to handle each incremental transaction, so its margins rise as payment volume rises. That means it could easily undercut the pricing of a smaller competitor, which makes it nearly impossible for a new payment card company to disrupt the status quo.

Even digital wallets like PayPal and Apple Pay lean on networks like Mastercard to facilitate card payments. In short, the company benefits from a virtually insurmountable moat.

Mastercard reported solid financial results in the fourth quarter, despite operating in a difficult economy. Revenue climbed 12% to $5.8 billion, and earnings based on generally accepted accounting principles (GAAP) increased 9% to $2.62 per diluted share.

As a caveat, growth might slow in the near term as high inflation and interest rates suppress business investments and consumer spending, but the company has powerful tailwinds and is in a good position to create value for patient shareholders.

Mastercard will undoubtedly benefit as mobile wallets and e-commerce drive an increase in payment card transactions. But its network also facilitates account-based payments like business-to-business transactions, and disbursements like digital wallet payouts.

Management believes that creates a $255 trillion market opportunity, but Mastercard reported a gross dollar volume of just $8.2 trillion last year, leaving the company with plenty of greenfield.

On that note, management expects revenue to grow in the low to mid teens over the long term. That makes its current P/S of 16 look reasonable. Investors should pick up a few shares of this stock today.