Closing your credit cards may sound like a smart financial decision if you’re in debt. After all, if you’ve racked up countless charges on your credit cards, you want to stop yourself before the situation gets even worse.

Before you close your debt-heavy accounts, know this: canceling credit cards can actually do more harm than good. Your credit score could suffer significantly and you could create a bigger financial disaster.

Here’s why it’s a better idea to keep your credit cards open even when you’re struggling with debt.

Your Oldest Credit Cards Boost Your Credit Score

Closing a credit card you’ve used for years could cause your credit score to take a serious hit. The length of your credit history accounts for 15 percent of your FICO score according to CreditCards.com1. Although it’s not the most important factor, your credit score could decline significantly if you close your oldest account.

For example, let’s say you’ve had the same credit card for eight years and you have a few other credit accounts, like a car loan and student loans, that are only four years old. If you cancel your credit card, the length of your credit history will drop from eight years to four years, and your credit score will decrease too.

Taking even just a few years off your credit history can seriously affect your ability to get out of debt. Lenders prefer borrowers with longer credit histories as they tend to be more trustworthy and responsible. And a longer credit history means your credit score gets a few extra points every year.

So, even if you have a high balance on your oldest credit card, keep it open – the age of your card will boost your credit score more than the balance decreases it.

More Credit Cards Means Better Credit Utilization

When you close a credit card, it affects your credit utilization ratio. Your credit utilization ratio is the ratio of your debt to your credit limit – and that ratio makes up 30 percent of your credit score according to CreditCards.com2.

A change in your utilization can have a major impact on your credit score. For example, say you charge $4,000 to a credit card with a $5,000 limit – but you have another card with a $3,000 limit and no charges. Because your total combined credit limit for both credit cards is $8,000, your credit utilization is at 50 percent. If you close the card with the $3,000 limit, though, your credit utilization will increase to 80 percent.

An 80 percent credit utilization ratio tells lenders and credit score companies that you’re relying heavily on credit to make ends meet. And this can result in a drop in your overall score. As The Balance3 reports, a good credit score usually means you must have a credit utilization ratio of no more than 30 percent. If you close a credit card, you’ll be reducing your available credit by thousands and potentially dropping your credit score significantly.

Credit Cards Diversity Your Credit

Your credit mix, or the different of types of credit you have, accounts for 10 percent of your FICO score according to myFICO.com4. Lenders want to see that you can successfully handle multiple types of credit, so having a good credit mix is essential for improving your credit score.

A credit card is a type of revolving account, or an account that allows flexibility for monthly payments. To have a good credit score, you should have at least one revolving account – but having more than one can be even better.

Closing a credit card can have a big impact on your credit mix, especially if you only have one or two cards. If you eliminate one of your credit types, you’ll see your score drop, especially if your credit is new and you have very few open lines of credit.

How to Know If You Really Should Close a Credit Card

Keeping your credit cards, especially if you’ve had them for many years, is usually better for your credit score than closing them. However, there are some situations where closing a credit card may be a wise choice. Here’s how to determine whether or not to close a credit card:

Consider the interest rates

If you’re carrying a large balance on a credit card with a high interest rate, paying off the debt should be a top priority. When the balance is finally paid off, you may want to close the card to avoid falling into high-interest debt again. As long as it isn’t your oldest credit card, you should be able to cancel your card without having much of an effect on your credit score. Your overall financial health is more important than your credit score in this case.

Look at the terms and perks

If you have multiple credit cards and want to get rid of one, the terms, fees, and perks can tell you which are the best to keep and which you should close. Cards with high interest rates, annual fees, and few perks can go, but you should hold onto cards with good terms. Also, cards with lower limits are typically better to get rid of than cards with higher limits as they don’t have as much of an effect on your credit utilization.

Cancel unused cards with annual fees

Annual fees can be acceptable if you receive great perks and rewards, but you should consider closing a card with an annual fee if you never use it. You’re not receiving any rewards to justify the fee, so you’re needlessly spending money. You can also try asking the credit card company to waive the annual fee if the card is old and lengthens your credit history.

You may be tempted to cancel all your credit cards to put all of your debt behind you, but you should carefully consider your credit score and your financial situation before closing any accounts. Your credit cards may lengthen your credit history, expand your credit mix, and improve your credit utilization ratio. Instead of canceling your cards, focus on paying off the debt while keeping the cards open to boost your credit score.