Employer-sponsored retirement plans like the 401(k) are the primary tool working people use to save for their golden years. People used to spend all or most of their working years with one company, but workers are much more likely to change jobs today.

Unfortunately, roughly 40% of people make a costly mistake when they switch occupations, potentially costing them thousands of dollars over the long run. So if you think you might get a new job at some point, read this so you're not unintentionally hurting your financial future.

4 in 10 people make this mistake when changing jobs

Too many people are cashing out their old retirement plans when leaving for new jobs. According to a study by Harvard Business Review, just over 40% of workers cash out at least a portion of their 401(k) plan when leaving or changing jobs. Most of those people, about 85%, withdraw all the funds.

Why? Everyone has their reasons, but the study found a correlation involving employer contributions. Essentially, the more an employer contributed to the 401(k), the more likely the employee was to drain their account. It would seem that some workers see employer contributions as free money, something more tempting to spend because it was given to them.

There are numerous upfront penalties for draining your retirement savings prematurely. For starters, you'll likely face a 10% penalty, and then have to pay income taxes on the funds you withdraw.

The actual cost is felt over time

But that's small potatoes compared to the lost compounding. You won't feel it right away, but it becomes painfully evident as the years go by. For example, suppose you're 30 and leaving your first job for a better career move. You've accumulated $10,000 in your 401(k), your first attempt at building a nest egg.

Hypothetically, you pay a 10% early withdrawal penalty, leaving you $9,000 before income taxes. For illustration reasons, let's keep taxes at a round number like $1,000. You spend the remaining $8,000 to take a fabulous vacation before starting your next job.

Had you kept that $10,000 invested in funds that earned an average of 10% annually by mirroring the S&P 500, you would have more than $174,000 after 30 years -- without adding another dollar. That's roughly what the typical 45- to 54-year-old worker has saved as their entire nest egg! You see, compounding does better work as time passes, and cashing out a retirement plan is like blowing up the compounding process and starting over.

Leaving your job? Consider these tips

Fortunately, you have several options when you leave your job. You can often keep your existing 401(k) with your former employer. You can also roll your 401(k) into your new employer's plan or an individual account like a traditional IRA.

The goal is not to touch your retirement savings just because you're changing employers. Is your balance filled with employer contributions? So what? Compounding works the same for a dollar you put in and for employer contributions. It's a disservice to your retirement savings efforts to cash out early.

Considering that America doesn't save adequately for retirement (the median retirement balance for a 65-year-old is just $87,000), it's a mistake most people can't afford to make.