The $3 million retirement mistake you could be making

Most retirement experts agree that a portfolio that includes stocks held over the long term is the surest way to amass the nest egg necessary for a comfortable retirement, but many millennials aren't getting the memo.

A 2016 Gallup poll found that just 38 percent of American millennials had invested in the stock market, down from 52 percent a decade ago.

Related: 15 Best States for Retirement in 2017

Still, the long-term impact of avoiding the stock market could be huge. A new NerdWallet report analyzed the potential savings of a 25-year-old with an annual salary of $40,000 who invested 15 percent of his annual income over 40 years.

RELATED: Check out the most popular places to retire in the US:

A portfolio fully invested in stocks over that period would amount to $4.57 million before inflation and after adjusting for investment fees. The same millennial who kept his money in savings would have just $1.27 million after the same period.

The hypothetical investor in the report would have more than a 99 percent chance of maintaining at least their initial investment, and a 95 percent chance of having at least $1.67 million. The median balance was $4.95 million, so the investor had a 50 percent chance of having more than that.

Still, most financial planners don't advise investors to remain 100 percent in stocks, and the analysis relied on historical returns, which may not hold in the future. To hedge against risk, investors should consider gradually mixing more conservative investments like bonds into their portfolios as retirement approaches.

More from The Fiscal Times:
15 Great Jobs for Retirees
What You Don't Know About Medicare Could Hurt Your Retirement
The Government Is Holding Millions in Unclaimed Retirement Money