How do banks mediate between those who have surplus money and those who need money?

Banks accept deposits from people who have surplus money, paying them interest on these deposits.
The banks use the major portion of the deposits to extend loans to those who need money, charging them slightly higher interest than what they pay to the depositors.
This difference is the major source of income for banks. In this way banks mediate between those who have surplus money and those who need money.