Experts often recommend saving up $1 million before you retire. But for many people, even $1 million may not be enough, thanks in part to longer life expectancies and disappearing pensions.

For those looking to give their retirement plan a boost, CNBC calculated how much you need to put into your 401(k) each month in order to reach $2 million by age 65, depending on when you start saving. Most financial planners suggest you put away anywhere between 10% and 15% of your gross salary for retirement, so CNBC also calculated the salary you'd need to earn in order to save $2 million without putting away more than 15% of your income.

It's worth noting that 401(k) plans come with contribution limits: In 2019, you can invest up to $19,000 in your account, up from $18,500 in 2018.

It's also important to remember that investing through a 401(k) or other retirement savings account should be seen as a long-term plan. It's impossible to predict future market returns, and investors should expect to experience both rises and dips in the market.

While these calculations don't take into account the many ups and downs people experience over their lives, such as pay increases, periods of unemployment or sudden financial windfalls or losses, it can be helpful to get a sense of what you should be saving to build a substantial retirement fund.

Here's how much you need to put away to save $2 million by age 65.