When your checking account drops close to zero, your next debit card purchase can cost you more in fees than you might expect.

If your bank covers the transaction and your account dips into the red, you can be charged an overdraft fee — not just once, but several times if you keep making purchases following a negative balance. The median cost of an overdraft fee is $34, so three purchases, for example, can mean more than $100 in fees.

This nightmare is avoidable if you follow some of these protective strategies.

» MORE: Overdraft fees by bank

Banks get to decide either to cover or reject a transaction that would make your balance negative, but you can control one thing. Opting out of an overdraft coverage program means that your bank cannot cover one-time debit card or ATM transactions or charge overdraft fees on them. Banks can cover checks and recurring debit transactions without asking for your permission.

Debit card transactions cause more overdrafts than any other transaction type, according to a 2014 report from the Consumer Financial Protection Bureau.

Without overdraft coverage, transactions get declined if there isn’t enough money, which likely will result in a nonsufficient funds or returned item fee. This fee usually is the same cost as an overdraft fee, but you’ll know you’re overdrawn, so as long as you don’t keep charging with your debit card, you can avoid additional overdraft fees.

Check your accounts weekly or even more frequently to make sure your balances aren’t too low. Most overdraft fees from debit cards happen with transactions of $24 or less, according to the CFPB. Balances can be checked online, via mobile app, by a phone call or by visiting an ATM or branch.

Automate the process of checking your balance. Find out whether your bank lets you set up email or mobile text alerts so that you get notified when an account goes below a certain threshold that you set.

When you know that a low balance has just triggered an overdraft, you might still be able to prevent an overdraft fee. See if your bank has a daily cutoff time, or deadline, for adding money to an account to correct a negative balance that same day to avoid fees. Even if you miss the cutoff, transferring money into the account soon can prevent other fees. Leaving a balance negative for several days, for instance, can result in an extended overdraft fee.

Your bank might also offer an overdraft protection transfer service. This involves linking a checking account to another account, such as a savings or credit account, at the same bank. When there’s not enough cash in your checking account to cover a transaction, money will be transferred from the linked account to cover the shortfall. There usually is a fee, but it’s cheaper than overdraft coverage fees. If you link a credit account, like a credit card or line of credit, you’ll have to pay interest on the overdrawn amount and possibly a transfer fee.

» MORE: Overdraft alternatives

If you continue having trouble keeping your checking account in the black, a prepaid debit card might be a solution. These cards work like debit cards, so you can deposit, withdraw and spend money, but they aren’t linked to checking accounts. Prepaid debit cards generally don’t have overdraft services or related fees, but they can have fees for declined transactions. Find a card with few fees that can provide the services you need.

» MORE: Best prepaid debit cards

These strategies can help minimize overdraft costs. In the long run, it’s better to have enough money in the account and avoid altogether a scenario where a transaction can be rejected by the bank.

Spencer Tierney is a staff writer at NerdWallet, a personal finance website. Email: spencer@nerdwallet.com. Twitter: @SpencerNerd.

Anisha Sekar of NerdWallet contributed to this report.

Updated Oct. 28, 2016.

The article How to Avoid Overdraft Fees originally appeared on NerdWallet.