Nvidia (NVDA -3.25%) has been a top stock for years, but it recently became a household name due its graphics processing units (GPUs) that power generative artificial intelligence (AI) applications. Demand for Nvidia's chips has skyrocketed, and that's reflected in soaring revenue and profits. Investors quickly pounced on the opportunity, and Nvidia stock is up 783% over the past two years alone.

Let's go back a little further and see where a $1,000 investment five years ago could have gotten you today.

It's not only the AI

Five years ago, generative AI was a concept strictly for tech people, but Nvidia was already a top chipmaker. It created the GPU in 1999 and transformed the gaming industry, and its chips are used in a variety of industries for data computing, including scientific applications and automotive. Because generative AI can be intensely consumer facing, Nvidia has become a recognizable symbol of its power.

Like most companies and industries, Nvidia has had its ups and downs. It gained 400% between the first two of the past five years, when the country was flooded with stimulus money and the markets were giddy with optimism. Then it lost a full 50% of its value with the resulting inflation and toppled markets. Smart investors held on and are now reaping the benefits of buying a great stock and holding through periods of volatility.

If you'd invested $1,000 five years ago, which would have been just before the pandemic and the ensuing market chaos, you'd have a staggering $31,500 today.

NVDA Chart

NVDA data by YCharts

Can Nvidia do it again? Long term, it has plenty of opportunities. There might be some short-term pressure since Nvidia already sports a high valuation and deals with building competition. But if you invest today, you should be richly rewarded down the line.