Saving $1 million for retirement may sound like an impossible task that not many people have achieved.

But about 157,000 people have saved at least $1 million in their 401(k)s with Fidelity, according to the company.

Another 148,000 had saved that much in an IRA.

Of those, 2,400 people had saved $1 million in both types of accounts.

So what's the secret to becoming one of them? Time.

Most of these people are Baby Boomers who have saved for at least 30 years.

"I think the most important behavior is to start saving early," said Katie Taylor, vice president of thought leadership at Fidelity.

That's good news for Millennials. If you're still in your 20s or 30s, you can set yourself up now to meet that goal with much less effort than an older person getting a later start.

People who've reached the $1 million mark also are saving a bigger percentage of their salary. Those with $1 million in their 401(k) are saving 24% of their salary each year — including both employer and employee contributions. Overall, the average 401(k) participant is saving 13%, according to Fidelity, the biggest plan provider by assets.

"The beauty of the 401(k) is that it takes the emotion out of investing," said Chuck Cumello, president and CEO of Essex Financial.

Since money is taken out of your paycheck automatically, you're less likely to try to time the market.

How do you stack up?

Less than 3% of Baby Boomers with a 401(k) at Fidelity have reached $1 million.

In 2016, working households aged 55 to 64 with retirement accounts had saved a median of $120,000, according to the Investment Company Institute.

It's no surprise that those with higher salaries have saved more. Those older households who earned more than $171,000 a year had saved a median of $600,000 while those who earned less than $35,000 a year had saved a median of $18,000. (The report considered assets in all defined contribution accounts, including both 401(k) and IRAs.)

Related: Are you behind on your retirement saving?

How can you get to $1 million?

Not everyone will need $1 million for retirement, Taylor said. One rule of thumb is to save 10 times your ending salary. If you're far away from retirement age, use an online calculator like this one to get an idea of how much you might need.

There are three common traits shared by those who have saved a lot of money in their 401(k)s, said Cumello.

1. Start saving early.

If you start at age 25, you'll need to save $650 a month to have $1 million by age 65. But you'd need to save $1,200 a month if you wait to start saving until age 35 (assuming a 5% average return).

Calculator: When will I be a millionaire?

2. Work toward saving the maximum allowed.

First, save at least as much to get the full company match, Cumello said.

Then increase your savings rate until you hit the federal limit. This year it's $18,500.

3. Pay attention to your investments.

Most 401(k)s have low-cost fund investment options. Cumello suggests investing in those to create a diversified portfolio. Avoid being too heavily invested in one stock.

Are you on track to save $1 million for retirement? Share your story with CNN Money.