We all would like to be millionaires by the time we retire. With Social Security income likely to provide only a modest fraction of the income we need, most of us will have to come up with the rest of our needed cash flows on our own.

Fortunately, if you invest regularly and effectively for a long time, you can achieve a comfortable retirement. The stock market is hard to beat for that -- but which stocks should you invest in? Here are some categories to consider.

Let's start with a little math, though, to help you see how you can become a millionaire. It takes time and diligence, and much will depend on how much you can sock away each year and how quickly it grows.

The table below shows how much you might amass over various periods, investing various amounts:

Data source: Calculations by author.

More in category

Supreme Court clerks see $400G bonuses from elite firms
September 21, 2020FOX Business
Supreme Court clerks see $400G bonuses from elite firms
Why Airline Shares Are Falling Today
September 21, 2020The Motley Fool
Why Airline Shares Are Falling Today
Why Carnival Corporation, Norwegian Cruise Line, and Royal Caribbean Stocks Just Crashed Again
September 21, 2020The Motley Fool
Why Carnival Corporation, Norwegian Cruise Line, and Royal Caribbean Stocks Just Crashed Again
Ellen DeGeneres Returns to Show With Apology for Toxic Workplace
September 21, 2020The NY Times
Ellen DeGeneres Returns to Show With Apology for Toxic Workplace
Volkswagen ID.4 electric SUV to come with three years of unlimited charging
September 21, 2020Reuters
Volkswagen ID.4 electric SUV to come with three years of unlimited charging
Wall Street slides to seven-week low on new lockdown fears
September 21, 2020Reuters
Wall Street slides to seven-week low on new lockdown fears
Opinion: Your retirement probably won’t be anything like your parents’…and that’s not good news
September 21, 2020MarketWatch
Opinion: Your retirement probably won’t be anything like your parents’…and that’s not good news
Why the Dow is diving: Ginsburg replacement battle amplifies election jitters
September 21, 2020MarketWatch
Why the Dow is diving: Ginsburg replacement battle amplifies election jitters
Mark Mobius warns on the biggest threat facing stock markets right now
September 21, 2020MarketWatch
Mark Mobius warns on the biggest threat facing stock markets right now
CNBC’s Jim Cramer says enough is enough: ‘This is the beginning of the end of the selloff’
September 21, 2020MarketWatch
CNBC’s Jim Cramer says enough is enough: ‘This is the beginning of the end of the selloff’
Monday’s stock selloff sets up the market for its worst September in 18 years
September 21, 2020MarketWatch
Monday’s stock selloff sets up the market for its worst September in 18 years
Anticancer drug team-ups show promise and here are 4 stocks that stand to gain
September 21, 2020MarketWatch
Anticancer drug team-ups show promise and here are 4 stocks that stand to gain
Here are 35 stocks in the market’s two hottest sectors that Wall Street loves
September 21, 2020MarketWatch
Here are 35 stocks in the market’s two hottest sectors that Wall Street loves
Opinion: Hope to retire someday? See if you can answer these six simple questions
September 21, 2020MarketWatch
Opinion: Hope to retire someday? See if you can answer these six simple questions
Opinion: Global banks hit by new corruption allegations. Why authorities are unlikely to act this time
September 21, 2020MarketWatch
Opinion: Global banks hit by new corruption allegations. Why authorities are unlikely to act this time
Stock-market selloff brings S&P 500 index on verge of correction, 3,222.76 is the level to watch
September 21, 2020MarketWatch
Stock-market selloff brings S&P 500 index on verge of correction, 3,222.76 is the level to watch
Nikola investors take a 'gut punch' as Trevor Milton steps down as chairman, Wedbush says
September 21, 2020MarketWatch
Nikola investors take a 'gut punch' as Trevor Milton steps down as chairman, Wedbush says
Opinion: The COVID-19 lockdown is squeezing real estate from all sides and threatens to burst the housing and mortgage bubble
September 21, 2020MarketWatch
Opinion: The COVID-19 lockdown is squeezing real estate from all sides and threatens to burst the housing and mortgage bubble
U.S. stock benchmarks skid, Dow off nearly 800 points and S&P 500 flirts with correction territory
September 21, 2020MarketWatch
U.S. stock benchmarks skid, Dow off nearly 800 points and S&P 500 flirts with correction territory
Bank stocks sink after report of alleged widespread money-laundering activities
September 21, 2020MarketWatch
Bank stocks sink after report of alleged widespread money-laundering activities
A financial crisis could surprise investors ‘sooner rather than later,’ warns Deutsche Bank
September 21, 2020MarketWatch
A financial crisis could surprise investors ‘sooner rather than later,’ warns Deutsche Bank