We have all done it - go out with some friends and split the bill, with someone paying using a debit or credit card and everyone else contributing cash. Sometimes the person making the debit takes the cash and deposits it into his her bank to cover the debit charge; cash, unlike checks, usually clears immediately, so this scenario should be no issue.
Depending on bank cutoff times, a deposit may not be counted until the next business day. At the same time, a corresponding debit may hit the account earlier. So if you deposit money into a bank at 11:01 PM after making a withdrawal at 10:55, for example, your deposit might not count as having been made until the next business day - and you may get thrown into overdraft for one day (or several days, if this happens over a weekend or holiday) if the debit hits sooner - generating a fee plus interest for the bank. (Debit card payments normally take a few days to settle, but they hit with pending status immediately.)
Here is the kicker: In some cases, it is even possible for a deposit made before a withdrawal to count as if it was made afterwards - you can literally deposit money and then withdraw some of it and get hit with overdraft fees. This mistake and various resulting problems happens to many people when they deposit checks and do not realize that check-funds may not become fully available for use for several days, but, in some cases, it can happen with cash too.
So, what is the lesson?
Unless you are willing to occasionally get hit with overdraft fees and interest, withdraw money from your account and/or make debit card charges against your account only when you know that the money is already available for withdrawal at the time the withdrawal/debit is made. (You could also learn, and follow any changes with, your bank's cutoff times, and be sure to always complete deposits beforehand.) Also, for security reasons, consider using a credit card instead of a debit card.
If you make a deposit this coming Friday night keep in mind that the next business day is Tuesday. Also, keep in mind that US banks make tens of billions of dollars a year in overdraft and NSF fees.
For more tips on staying safe while using credit cards please see my article 11 Tips To Help Keep You Cyber-Safe When Shopping Online. And for tips on keeping yourself safe, please see 15 Personal Safety Tips That Could Save Your Life.