A few weeks ago, two friends told me they were going to start shopping for a new car.

The search, frankly, is long overdue. Right now, the couple shares a small hatchback that first hit the road when we all still had bedtimes. They affectionately call it "Daisy," but it looks and smells a lot more like an old lemon.

They said they wanted to replace Daisy with a used Subaru that would probably cost around $14,000. It would be their first big expense as a couple, but they said they weren't too worried about it because they had the money to buy the car outright, without a loan.

I begged them to reconsider and started giving them a spiel about how some of that money was probably better off being invested...but we quickly tabled the talk for another time, because there are far more fun things to talk about at a bar on a Friday night.

I'm rehashing that conversation now, because I'm "that friend," and because a lot of people default to avoiding debt without considering what else they could do with their money.

My friends' cash-first mentality is the product of years of conventional wisdom telling them to avoid debt whenever possible. And in this case in particular, why would they want to pay interest to get access to an amount of money that they already have?

But when it comes do debt, as with many things, you need to learn the rules early so that you can break them once you've established good habits. Because the reality is that there is a cost to making a big purchase in cash, and it's a lot bigger than the interest my friends might pay on an auto loan they don't need.

The opportunity cost

Let's say that instead of buying in cash, they decide to put roughly 20% down for the car and finance the rest. We'll round the down payment here to $3,000, so they'd be looking for an $11,000 loan. Someone with good credit looking for a loan that size with a 60-month term would likely qualify for an APR -- or borrowing cost -- somewhere between 3.25% and 4.5%.

At the higher end of that range, they'd spend roughly $12,300 total paying off the car. For the additional $1,300 they'll pay in interest, my friends get optionality. They can do anything they want with the $11,000 they aren't immediately paying for the car.

Assuming they've built up a comfortable emergency fund, that lump sum can be invested and they can make the roughly $205 monthly car loan payments with money from their paychecks. Here's a table breaking down how that $11,000 might grow over five years at different returns if they decided to put the money in a mutual fund or individual stocks.

Annual Investment Return Year 0 Balance Year 5 Balance Total Gain Gain Net of Interest on Car Loan* 3% $11,000 $12,752 $1,752 $452 5% $11,000 $14,039 $3,039 $1,739 7% $11,000 $15,428 $4,428 $3,128 9% $11,000 $16,925 $5,925 $4,625

Even at a measly 3% annual growth rate, choosing to invest the money could net my friends over $400 more, after accounting for the interest paid on the loan.

It might seem counter-intuitive that you can beat a 4.5% interest rate with 3% investment returns -- the reason these numbers work is that the balance that higher interest rate is being applied to is being whittled down over time, while the lower investment return rate winds up being applied to a growing base. It's a beautiful instance of compounding at work.

If their money earned closer to the historical stock market average of 7%, then their decision to finance the car and invest their cash on hand would net them several thousand dollars more by the time they paid the loan off.

So in the short term, there's a benefit to not buying the car outright in cash. But when you look at the long term, the numbers become staggering. That $11,000 figure I landed on before wasn't exactly arbitrary; it's enough for two people to max out their annual Roth IRA contributions for 2017.

If my friends decided to do that, they'd be committing to not touching the account until they reached retirement age, which would give their money roughly 30 years to grow. Here's another table breaking down what that $11,000 could grow to at different rates of return.

Annual Investment Return Year 0 Balance Year 30 Balance 3% $11,000 $26,700 5% $11,000 $47,541 7% $11,000 $83,735 9% $11,000 $145,944

Earning around the market's average return, they would have four times as much money as they originally put in by the time they started drawing on the account, thanks to a long time horizon and compound interest. And whenever they decided to take distributions from it, they'd be able to do so without (likely) paying any taxes.

Taking that view, the $1,300 they'd pay in interest is tiny relative to the thousands of dollars in retirement money they'd be forgoing by paying for the car in cash up front now.

It's good to have options

I mentioned optionality before, and that's a luxury of having cash on hand. Building up thousands of dollars in savings isn't easy, so when the time comes to do something with it, it's always worth weighing the options.

Investing is just one way they could use they could use the cash. If they have existing credit card or student loan debt with higher APRs than the auto loans they'd qualify for, it might make sense for them to finance the car and pay down those other accounts with the money they've saved.

There are a couple of caveats to all of this:

The numbers aren't going to work this way for everyone weighing a car purchase. Unfortunately for people with average or poor credit, the higher the APR, the less likely it is that the investment returns will outweigh the cost of the loan.

Financing the car only makes sense if you're confident you'll be able to make the monthly payments throughout the loan term.

That 7% average stock market return I cited is based on decades of data. There are five-year periods that have crushed that average (such as 2012-2017) and five-year periods that have dramatically underperformed it (such as 2006-2011). This just reinforces why it's best to look at investing with a long time horizon.

There's one golden rule to remember with loans: Don't let credit stretch your budget. In my friends' case, they shouldn't be willing to spend more than they'd originally planned just because they have access to more money.

Some people, even after running through the numbers, would rather buy the car outright because they don't like the feeling of having debt looming over them. It may not be the best financial decision, but again, having money saved up gives you the ability to choose your own adventure.

As Groucho Marx once said, "While money can't buy happiness, it certainly lets you choose your own form of misery."