Legendary investor Warren Buffett once said that someone is sitting in the shade today because someone planted a tree a long time ago. It's a great quote about long-term thinking, which translates directly to building wealth through investing.

The goal of any long-term investor should be to find great companies and hold them for a lifetime, letting them lift your portfolio for you. However, that's not easy, because so few companies deserve permanent places in your portfolio.

Buffett's Berkshire Hathaway (BRK.B -0.69%) and technology giant Microsoft (MSFT 1.82%) might be as strong a long-term bet as you'll find in the market, and you can buy both for under $2,500. Here is what separates them from the pack.

A company led by Earth's greatest long-term investor

Berkshire Hathaway is Buffett's holding company, the crown jewel of his vaunted investing career. The company owns many businesses, brands, and positions in other public companies. Its largest business segments include railroads, oil and gas pipelines, and insurance, while blue-chip stocks like Apple, Bank of America, and Coca-Cola anchor Berkshire's stock portfolio.

Buffett built Berkshire Hathaway in his image, focusing on resilient business models that never go out of style. That's why Berkshire has owned Geico Insurance since 1995, and has held some of its stock holdings since the late 1980s. Buffett also ensures Berkshire is always well-funded; it has more than $157 billion in cash and short-term investments on its balance sheet today.

Berkshire's earnings based on generally accepted accounting principles (GAAP) fluctuate because of how many moving pieces the company has, but owning the stock is as close as you can get to having Buffett invest on your behalf. And the record speaks for itself: Berkshire's book value has exploded, beating the S&P 500 for decades.

BRK.B Book Value (Quarterly) Chart

Data source: YCharts

Nobody can guarantee the future, but there isn't much reason to doubt Berkshire. Buffett won't be there forever, which may be Berkshire's biggest risk. Still, one would think he's been preparing for the inevitable, instilling a culture that will carry the company after he's gone. Buffett has even handpicked his successor, naming Greg Abel as the company's next chief executive officer.

The technology titan that keeps evolving

Technology giant and personal computing pioneer Microsoft could be the world's most innovative company. It's hard to stay on top in the technology sector because innovation keeps companies on their toes and creates new competition. But not only are Microsoft's legacy products like its Windows operating system still market-leading brands today, the company has penetrated other markets with leading products, including cloud computing, video gaming, and enterprise software.

Added together, these businesses create cash flow like few others on earth. Annual revenue surpasses $218 billion, and $63 billion of that is free cash flow, an impressive 29% conversion rate. Microsoft carries $144 billion in cash and short-term investments against $71.5 billion in long-term debt from acquiring video game company Activision Blizzard. Microsoft's financials are considered so strong that the company has a coveted AAA credit rating from Standard & Poor's, higher than that of the U.S. government!

Microsoft also has long-term growth opportunities lined up. Azure is the world's second-largest cloud platform after Amazon Web Services. Demand for cloud services should explode, and is forecast to more than double to $1.24 trillion by 2028. The company has tied itself up with OpenAI, the artificial intelligence company behind ChatGPT. Despite recent uncertainty, OpenAI positions Microsoft to benefit from AI's future potential.

MSFT Normalized Diluted EPS (TTM) Chart

Data source: YCharts

You can see what successful innovation has done for the company's growth. As long as Microsoft stays aggressive, it's hard to see its fortunes reversing anytime soon. Investors can slowly buy Microsoft stock and sock it away for years. There aren't many companies you can say that about.