You have good reason to flinch every time you withdraw cash from an out-of-network ATM. The cash machine operator and the bank each hit you with a separate fee for these withdrawals, and both types set record highs this year, according to a new Bankrate survey.

In Phoenix and Atlanta, grabbing cash from an out-of-network ATM will set you back more than $5. But even the cheapest metro area isn’t actually much less expensive: In San Francisco, the average fees are now $3.90. “The national average is $4.57, which means stopping at an out-of-network ATM for $20 will cost nearly 23 percent in fees,” says Greg McBride, CFA, Bankrate's senior vice president and chief financial analyst.

To skirt the fees, stay in network. Virtually any bank will let you withdraw money from its own ATMs, of course. But if you want easy, low-cost access to more cash machines, ask your bank if they participate in a larger ATM network. Some do, to provide their customers with more widespread access.

While ATM fees climbed higher in 2016, one type of bank fee actually broke its 17-year streak of increases: overdraft fees. The average is now $33.07 (yikes!), but that's 0.1 percent below last year’s average. It’s probably too soon to celebrate the downward trend, says McBride. Overdraft fee increases still outnumbered decreases by 5 to 1 in the national survey.

McBride’s best advice for avoiding the hefty penalty? “Sign up for email and text alerts that let you know when your balance is getting low, so you can proactively move money into the account,” he says. “And keep tabs on your available account balance through online and mobile banking—particularly before initiating transactions.”