There are times when a credit card no longer works for your needs, and you decide to close it. Or a credit card provider closes your account due to inactivity or because you made too many late payments, or worse, let the account become delinquent. Closing the account could put an end to your troubles, as long as you pay your balance off in full. But don’t breathe a sigh of relief just yet — the account doesn’t just go away, it will remain on your credit report for several years, affecting all of your future credit needs. How long do closed accounts stay on your credit report? Here’s everything you need to know to protect your credit score:

Closed accounts and your credit

As mentioned, a closed account doesn’t just disappear overnight from your credit history. In some cases, you wouldn’t even want to close an account. If the account was closed for a negative reason, such as too many late payments or a failure to pay the card leading to a charge-off, the closed account would stay on your report for seven years. Every creditor who reviews your credit history will see the mention of the account’s shaky past. If the account was closed in good standing with a good payment history and no outstanding balance, the account will remain on your credit for at least 10 years.

A closed account typically hurts your credit score if it was closed for a negative reason. If a closed account is in good standing, it could continue to benefit your credit history, although there are other factors to consider. The three major credit bureaus use five factors to score your credit history, including payment history (35%), new credit and number of credit inquiries (10%), credit age (15%), credit utilization ratio (30%) and credit mix (10%). Taking the last three factors into account (since the first don’t apply to closing an account), more than half of your FICO can be negatively affected by a closed account. Here’s how:

Credit age: The length of your credit accounts makes up 15% of your credit score. Creditors see long-standing credit accounts as a sign that you’re financially stable. Your account ages are averaged for a score. The longer your average account age, the better. If the account you closed was older than some of your other accounts, it could end up lowering your credit score. Imagine you have three accounts. The first is five years old, the second is three years and the third is one year old. Your average account age is three. If you close your oldest account, your average account credit age is now 1.3 years old.

Credit utilization: Since it accounts for 30% of your credit score, a closed account can quickly drop your score. The credit bureaus will divide your total available credit and the outstanding balance of all your cards to find your credit utilization ratio. If you have a total of $6,000 in available credit and carry a balance of $1,500 on all your cards, your credit utilization ratio is 25%. Anything under 30% is considered acceptable by creditors. Now imagine you close a credit card that had a $1,500 credit limit. Your total available credit is now $4,500. The $1,500 balance on your cards raises your credit utilization ratio to 33%, which could negatively affect your credit score.

Credit mix: In investing, you should diversify your portfolio to reduce your risk. The same goes for credit — the bureaus and lenders like seeing you have a diversified history of credit products. They see a variety of credit types in good standing as your ability to be financially responsible. It’s worth 10% of your total credit score.

Think twice before closing an account

Avoid closing an account unless it’s costing you more than you can afford. For example, if you have a credit card that you rarely use with a $95 annual fee, it’s probably worth closing. After all, a dip in your credit score may be worth the nearly $100 annual savings. Avoiding cards or credit products that come with high fees unless you’re positive that you’ll utilize the card and its rewards would save you from having to close them in the future.

If you’re considering closing a credit card, some alternatives could protect your credit history. Ask your credit card issuer if they can switch your card to a no annual fee version. Check the terms and conditions on your lines of credit or card products. Some waive fees if you make a minimum amount of transactions. Other issuers may close your account if you don’t occasionally use it, so it’s important to know the rules associated with your open lines.

A credit account will stay on your credit report for years, even if it’s closed. How long do closed accounts stay on your credit report depends on whether the account ended negatively or in good standing. That’s why it’s essential to make your payments on time and carry low balances. Before you open a credit line or card, know what you’re signing up for and what the fees that come with the account are. Making smart choices and knowing how to maintain your accounts in good standing from the start will save you from having to close the account later, potentially affecting your credit score.