At one point,
gold was used as the
medium of exchange much like
dollars are today. Like dollars, people wanted a safe place to store their gold - thus the
bank. Rather than having to physically carry around their gold (or their dollars), banks allowed people to write a
check - an
instruction to the bank to transfer their gold (or dollars) from their
account to someone else's.
This kind of check writing became so common, that people began to trust the bank's account records, rather than bothering to physically move the transfered gold (or dollars) from the old safety deposit box to their own.
Since gold (and dollars) no longer had to be physically moved, banks realized they could now fudge their records - increase a person's account balance without actually having the gold (or dollars) to put in it. Thus the loan was invented. As long as everyone didn't withdraw their gold (or dollars) at the same time, the bank could simply use other people's gold (or dollars) to cover individual withdrawals.
Loans were such a profitable side-business that they soon became the primary business of banks. Thus we have modern banking, the creation of credit money out of nothing, and the ever present threat of runs on banks.