IT IS like magic. By clicking a few keys on a mobile phone, money can be zapped from one part of Kenya to another in seconds. For urban migrants sending money home to their villages, and for people used to queuing at banks for hours to pay bills or school fees, the M-PESA money-transfer service, operated by Safaricom, Kenya's largest mobile operator, is a godsend. No wonder it is used by 9.5m people, or 23% of the population, and transfers the equivalent of 11% of Kenya's GDP each year; or that it has inspired more than 60 similar schemes across the world.

But despite the apparently frictionless transfer of money through the air, making a money-transfer system work smoothly requires a great deal of backstage effort. Jake Kendall and Ignacio Mas of the Bill & Melinda Gates Foundation, and Frederik Eijkman of PEP Intermedius, a financial-services firm, explain how it all works in a paper presented in late May.

The basic idea of M-PESA is that the 100,000 small retailers in Kenya who already sell mobile-phone airtime, in the form of scratch cards, can also register to be mobile-money agents, taking in and paying out cash. More than 17,600 retailers have signed up as M-PESA agents—far outnumbering Kenya's 840 bank branches. When a customer is registered with the system, paying in cash involves exchanging physical money for the virtual sort, called “e-float”, which is credited to his mobile-money account. E-float can then be transferred to other users by mobile phone, and exchanged for cash by the recipient, who visits another agent.

It is simple enough for customers. But agents in cities, where most transactions are deposits (see chart), accumulate cash and risk running out of e-float, at which point they cannot take any more deposits. Agents in rural areas, where most transactions are withdrawals, accumulate e-float and risk running out of cash. Keeping the system running requires the agents to manage their liquidity, by regularly swapping cash for e-float, or vice versa.

Exchanging cash for e-float means visiting a bank affiliated with Safaricom, and the whole point of systems like M-PESA is to reach where banks cannot. Accordingly, M-PESA relies on a system of intermediaries (including Mr Eijkman's firm, PEP Intermedius) between agents and banks. These middlemen have their own distribution networks, and take on much of the work of ferrying cash around the country. But individual agents still handle the “last mile”.

The paper's authors give the example of Gaudencia, a woman who owns three shops in western Kenya, each about 30 minutes by bus from the others. She spends her days shuttling between her three stores and the office of her local intermediary, transferring cash and e-float to where they are needed most. At times she carries more than 75,000 Kenyan shillings ($1,000) in cash, but says she has never been robbed. She spends around $5 a day on bus fares, a typical daily wage in her part of the world, but she earns around $1,000 a month in commission from the M-PESA transactions in her three shops.

In short, Gaudencia pools the transactions of her customers and her intermediary pools the transactions of many such agents, cushioning them from the clearing delays within the banking system. Rather than many individuals moving money around by carrying it physically, as they had to in the days before M-PESA, the movement of money can then be handled in larger quantities by a smaller number of individuals, which is much more efficient. Safaricom, says Mr Mas, “understood this like no other mobile operator really has”. As well as orchestrating the emergence of the intermediaries, it monitors its agents closely, typically visiting them every two weeks to see how they are handling the growing volume of transactions (on average, each M-PESA agent now handles almost 100 transactions a day).

Operators in other countries have been doing their best to imitate Safaricom. The most ambitious is Africa's biggest operator, MTN, which is rolling out mobile-money schemes in several African countries. Its scheme in Uganda has signed up 890,000 users since its launch in March 2009, and is expected to reach 2m by year-end.

There are many elements to a successful mobile-money scheme: the right technology, simple marketing, partnerships with banks, support from regulators. But keeping it all going are people like Gaudencia, moving bundles of cash around, on buses and in vans, behind the scenes.