Experts often recommend saving up $1 million before you retire. While many people are able to live on much less than that, for others $1 million may not be enough, thanks in part to longer life expectancy and disappearing pensions. At the same time, many financial planners also suggest saving anywhere between 10% and 15% of your gross salary. But to be able to comfortably save while also building a multi-million-dollar retirement fund, you'd need to earn a substantial salary. In most situations, that means bringing in far more than $61,372, the median household income in the U.S. Below, CNBC calculated the amount you need to earn annually in order to save $2 million by 65 by putting 10% of your earnings into investments.

If you start at age 25:

With a 4% rate of return, you need to earn $202,378 per year and save $1,686.48 per month (exceeds the $19,000 annual limit on 401(k) contributions)

and save $1,686.48 per month (exceeds the $19,000 annual limit on 401(k) contributions) With a 6% rate of return, you need to earn $120,513 per year and save $1,004.27 per month

and save $1,004.27 per month With an 8% rate of return, you need to earn $68,748 per year and save $572.90 per month

If you start at age 30:

With a 4% rate of return, you need to earn $262,659 per year and save $2,188.83 per month (exceeds the $19,000 annual limit on 401(k) contributions)

and save $2,188.83 per month (exceeds the $19,000 annual limit on 401(k) contributions) With a 6% rate of return, you need to earn $168,455 per year and save $1,403.79 per month

and save $1,403.79 per month With an 8% rate of return, you need to earn $104,626 per year and save $871.88 per month

If you start at age 40:

With a 4% rate of return, you need to earn $466,808 per year and save $3,890.07 per month (exceeds the $19,000 annual limit on 401(k) contributions)

and save $3,890.07 per month (exceeds the $19,000 annual limit on 401(k) contributions) With a 6% rate of return, you need to earn $346,323 per year and save $2,886.03 per month (exceeds the $19,000 annual limit on 401(k) contributions)

and save $2,886.03 per month (exceeds the $19,000 annual limit on 401(k) contributions) With an 8% rate of return, you need to earn $252,359 per year and save $2,109.99 per month (exceeds the $19,000 annual limit on 401(k) contributions) For context, the average American's 401(k) plan grew at a compound annual average rate of 14.2% between 2010 and 2016, according to a study of more than 6 million accounts by the Employee Benefit Research Institute, a nonprofit based in Washington, D.C. Of course, there's no guarantee of similar growth in the future. Keep in mind that these numbers don't take into account the many ups and downs you may experience over your lifetime, including periods of unemployment or sudden financial windfalls or losses.