Extending college for more than four years not only increases the cost of tuition and student borrowing, but it can also dent income and retirement savings, according to a new analysis by the website NerdWallet.

That's because when students are in school for an extra year or two, they pay more in tuition and debt and are not earning a salary or contributing to retirement savings.

Students who take six years to finish a bachelor's degree, for example, can miss out on six figures of lifetime retirement savings, NerdWallet estimates.

Just 40 percent of college students finish their bachelor's degree in four years, said Nonso Maduka, student loan specialist at NerdWallet, citing data from the National Center for Education Statistics.

NerdWallet used data from the National Association of Colleges and Employers to do its analysis. It considered the group of students who began college in 2008 and intended to graduate in 2012, but instead finished in five years or six years.

A common reason for taking longer than four years is transferring to another school; that switch can often result in lost credits. Some are caught in a tough predicament: They must work to pay for college, but working longer hours means they may take a lighter course load and therefore take longer to finish.

NerdWallet based its analysis on average tuition costs at public and private nonprofit colleges, as well as the cost of student loans at an interest rate of about 5 percent.

The cost of taking one extra year to finish a degree at a public college is about $12,600 in out-of-pocket tuition and $6,000 in loan costs over 10 years, for a total of about $18,600. Two extra years at a public college total $37,500. Costs are higher for private schools; the cost of two extra years at a private college is almost $54,000.

The resulting hit to retirement savings is sobering. The analysis assumed graduates would put about 7 percent of their income into a retirement plan (the average contribution rate for people under 25), and that the savings would compound over 45 years at a 7 percent annual return.

On that basis, students who graduate from college in five years would miss out on about $82,000 in retirement savings, and six-year graduates would fail to gain as much as $151,000.

A student who spends two extra years at private school, therefore, can accrue extra costs of nearly $300,000 overall, factoring in tuition, debt and missed income and retirement savings.

"Know the trade-offs you're making," Maduka said.

Ann Carrns writes for the New York Times.