At the core of long-term investing is the idea that if you pick the right companies, and hold on to their shares for years (not weeks or months), you'll be able to outpace the gains made by the broader market.

Applying this strategy is easier said than done, but it's not impossible. And to get it right, you need to start with the right companies. That's why we reached out to three Motley Fool contributors for a few stocks that investors should consider holding on to for a really long time -- like 20 years. They suggested taking a look at Canadian National Railway (CNI -0.56%), Fluidigm (FLDM -0.72%), and (AMZN 0.11%)

Pocket watch sitting on top of money.

Image source: Getty Images.

An anchor for your portfolio

Neha Chamaria (Canadian National Railway): Twenty years from now, no matter how much the world changes, one thing is unlikely to change: the need to transport goods from one place to another. Transportation, after all, is the essence of commerce and trade, without which economies would come to a standstill. That is why I believe a railroad giant like Canadian National Railway should not only still be around decades from now, but should also be chugging along nicely on the growth track.

To be sure, innovations such as automated trucks pose a threat to railroads, but it's too early to predict if and how futuristic technologies like driverless trucks will hit the mass market. More important than that, railroads inarguably remain the preferred mode of transportation of goods over long distances; whether trucks can ever displace railroads on that front is all but a wild guess today.

I see little reason to worry for a company like Canadian National, which is the only railroad in North America to connect customers to all NAFTA nations through its expansive three-coast network spanning the Atlantic, Pacific, and Gulf Coasts. That's not all: Canadian National is also among the most cost-efficient railroads, and its management has been nimble enough to swiftly respond to challenges to minimize erosion in shareholder value over the years. To give you an example, the company ousted its CEO and fast-tracked a major expansion program last year to overcome unanticipated inefficiencies.

Its plans to pump record sums of money into infrastructure this year should position Canadian National for solid growth in the years to come. Meanwhile, investors can also count on the company for steady and growing dividends: Canadian National has increased its dividend every year since 1996. Overall, I believe this railroad stock is one of the best long-term bets in an industry that drives the economy.

A small-cap beneficiary of the fast-growing biopharma sector

Maxx Chatsko (Fluidigm): One of the hottest areas of study in the biopharma industry right now is immunology, which focuses on harnessing the innate power of the body's immune system to treat diseases. While experimental treatments and the companies developing them tend to grab all the headlines, companies on the periphery are arguably just as important to the sector's innovation pipeline. Fluidigm is a great example.

The $900 million business manufactures laboratory equipment that makes it possible to study complex biological samples and systems in impressive detail. The most lucrative opportunity for Fluidigm -- and the one that could finally make the business profitable -- is something called mass cytometry, which can map out the complex networks used by cells to communicate. Data generated from mass cytometry machines can point to previously undiscovered proteins and antibodies with therapeutic potential, determine how drugs affect various organs, and help researchers compare novel ways to efficiently deliver gene editing or gene therapy drugs.

The importance of mass cytometry to the overall business was crystal clear from full-year 2018 operating results. Revenue from mass cytometry jumped 27% year over year, while all other segments combined saw a 3% decline in sales. Total revenue still increased 11% in that span. More important, the high margins of mass cytometry machines allowed Fluidigm to grow revenue without increasing operating expenses, which allowed all of the revenue increase to flow down the income statement as profit.

Considering that the business posted an operating loss of $48 million and operating cash outflow of $25 million in 2018, shareholders will likely have to wait at least two years for profitable operations. It's also worth noting that a surge in stock price in recent months makes shares a little pricey right now, trading at nearly 8 times sales and 9 times book value. But if Fluidigm can continue to exploit the lucrative niche of mass cytometry and develop additional equipment that leverages its expertise in single-cell analysis, then it should be able to grow into its valuation over time -- and then some. 

An e-commerce giant with a tech twist

Chris Neiger ( Amazon hardly needs an introduction. Nearly half of all online U.S. retail sales happen on the company's platform, and its influence over new industries continues to spread. Amazon's Prime Video creates award-winning content, its Alexa devices are making smart gadgets and connected homes a reality, and its takeover of Whole Foods shows that the company will move in any direction it wants.

But despite the company's massive online sales, its more than 100 million Prime members, and its push into the grocery industry, Amazon's real long-term potential lies in the company's ever-expanding tech ambitions. Right now, Amazon is the No. 1 public cloud computing company with about 32% of the market. Think about that for a moment: The same company that delivers toilet paper to customers' doors also has the premiere cloud computing company.

And not only is it dominating the cloud market, but it's also making the majority of its profit from the business. Even with all of its online sales, Amazon Web Services (AWS) still brings in more operating profit than its retail business. Why does that matter for long-term investors? Because the public cloud computing market is already worth $206 billion right now, and it's growing into a $278 billion industry over the next few years. As it grows, there's no doubt Amazon's early lead in the market will continue to pay off.

So investors looking for a company that they can safely bet on for the next two decades need to look at Amazon. The company's online retail dominance in the U.S. is unmatched, and its big bet on cloud computing is already paying off. As these two industries grow, Amazon -- and its investors -- are likely to benefit.