With a swipe here and a swipe there, it can be easy to live your life on plastic and pile up debt. You’re not alone: U.S. households carried credit card balances that totaled $815 billion in debt in the first quarter of 2018, according to the Federal Reserve Bank of New York.

Sticking to a budget, spending wisely and focusing on your financial goals can help you use your money for the things that are most important to you — without taking on the burden of credit card debt. Here are three strategies to help you avoid the debt trap.

Set a budget to know your limit

Staying out of debt starts with knowing how much you can (and can’t) spend. A realistic budget is the foundation. Take into account everything you spend money on, such as movie tickets, loan payments and groceries.

“Think of your budget as a rulebook to follow,” says Lacey Langford, a financial coach based in Summerfield, North Carolina. “You can’t make a game plan or stay on track if you don’t understand how much money you have going in and coming out. Once you have that, you have a good gauge for making financial decisions.”

An easy option is the 50/30/20 budget:

  • 50% of your income goes to necessities, such as housing.
  • 30% can be used for wants, like eating out at restaurants.
  • 20% goes to pay debt and save money.

Be sure to also consider expenses that don’t occur monthly, like annual membership fees or car maintenance, which could derail a carefully planned budget, Langford says.

Spend strategically (and frugally)

When managing your budget and disposable income, spend where your priorities and goals are and cut costs elsewhere to avoid debt. This approach can also free up more cash for your goals, such as saving to buy a home or retire early.

You may end up making changes to your budget to help align spending with your goals, such as:

  • Buying a used car instead of a new one.
  • Packing lunch or making dinner instead of eating out.
  • Making purchases on sites like Craigslist and Facebook marketplaces.

“Make your principles the priority, then spend accordingly,” says Brandy Baxter, a Dallas area financial coach. “For me, family is very important, so I’ll spend more on things for my family and less on other material possessions.”

You can also trim expenses by shopping smarter. Small savings from using things like coupons and price comparison apps before making a purchase can add up.

Save money to prepare for the worst

It’s inevitable: A hospital stay will leave you with bills that you didn’t plan for, or your car will break down. Unexpected expenses can clobber even the most carefully planned budget, but an emergency fund can help you weather the storm.

“Having money to help you pivot when something happens will help you avoid going into debt,” Langford says. “You need a surplus of cash to buffer your budget for when things happen.”

Start small. Examine your budget to find $50 or $100 you can put aside each month for an emergency fund. Once you’ve saved enough to cover a few months of expenses, see if you can keep it going. Set up automatic transfers into a designated emergency savings account, so you can build up a reserve without having to think about it.

The article 3 Simple Things Anyone Can Do to Stay Out of Debt originally appeared on NerdWallet.