A good target for retirement is $1 million. That can give you a good nest egg to pull money out of as you need, or you can invest it into high-yielding dividend stocks or a diverse exchange-traded fund that brings you recurring income. But just how much do you need to invest to get to $1 million realistically? That depends mainly on two things: First, what growth rate you expect your investments to grow at, and second, how many investing years you have left.

Where should you invest, and what returns should you expect?

A realistic long-term target for investors may be the S&P 500's average, which is around 10% per year when including dividends. Over the past decade, the index's total returns (including dividends) have been about 240%. Focusing on growth stocks can be a way to outperform the index; for example, drugmaker Eli Lilly, and managed healthcare company UnitedHealth Group, have dwarfed those numbers with total returns of 875% and 1,000%, respectively, during that same period.

The healthcare sector, as a whole, has been known to offer investors an excellent option for long-term gains. The companies in this sector not only offer long-term stability due to the nature of the products and services they provide, but they also possess attractive growth potential. And they can make for resilient investments. This current bear market is a harsh reminder of how quickly investments can unravel with the S&P 500 down 18% year to date. However, both Eli Lilly and UnitedHealth have continued to outperform the markets this year, with their shares up 19% and 3%, respectively. Even the Health Care Select SPDR Fund is only down 8% this year; there are no shortage of quality stocks to choose from in the sector. 

When you're planning for retirement, it's important to balance safety along with growth. Healthcare is essential and that can make the industry a safer option to invest in than tech or even consumer goods. And by targeting companies that are always pursuing growth with strong fundamentals, like Eli Lilly and UnitedHealth, you can put yourself in an excellent position to generate some strong profits in the future.

The more investing years you have left, the less you need to invest today

The next key variable to account for is investing years. After factoring in an assumed 10% growth rate, this will help determine how much you should invest right now. You're always in a much better position the earlier you start investing. But the downside is when you're young, you may not have that much money to set aside for stocks. The good news is you can always make up for having less time by investing more money. 

Here's how much you would need to invest at varying stages of your life if you were to average 10% annual gains:

Calculations and chart by author.

Another assumption here is that you retire by age 65. Although $13,719 seems like a small amount to invest, with 45 years of compounding those 10% gains would increase your investment value by 7,189%. That means your investment would be worth nearly 73 times what it was when you first invested the money. The loss of investing years is evident by age 50. With only 15 years until retirement, your investment would increase by a more modest 318% if it averaged 10% gains per year. By then, you would need nearly $240,000 ready to invest in the stock market to have a realistic expectation of getting to $1 million by retirement.

Getting to $1 million by retirement isn't an unreachable goal, and by knowing how much you'll need to invest by a certain age, you can plan ahead and set yourself up for a brighter future.