Banks (like everybody) use double entry accounting. When they make a loan, there are two entries. One is a credit to your account for the amount of the loan, the other is a debit representing the debt you now owe to the bank. You borrowed $5000, so you owe the bank $5000 (the loan) and they owe you $5000 (it's in your checking account), which cancel out. Notice that the amount of cash in their vault hasn't changed at all.
Banks have reserve ratios. They're required to keep a certain amount of their deposits on hand in case somebody actually wants to withdraw them. (Those just got set to zero, but they're normally something like 10%.) But as long as they've satisfied their reserve requirements, they create money from nothing when they make a loan.
When you pay back the loan, the debt of the loan and the credit in your deposit account cancel each other out again, they both disappear and the money that was created is destroyed along with your debt.