This article was first published in the October 2017 UK edition of Accounting and Business magazine.

Writing is a miraculous invention – so much so that people used to believe that it was divinely inspired. Ancient Egyptians thanked baboon-faced Thoth, the God of Knowledge, for the gift. Greeks gave the credit to Prometheus. Mesopotamians thought that Enki, the God of Wisdom, had got blind drunk – not obvious evidence of wisdom, it must be said – and that during Enki’s stupor, the Goddess Inanna stole from him the secret of literacy.

The ‘baboon-faced Thoth’ theory of writing’s origins is now out of favour with archaeologists. But in truth, the origin of literacy was a puzzle for a long time. One idea was that writing was used to send messages to distant armies. Another theory is that it was used for poetry or religious texts.

In 1929 the mystery deepened. A German archaeologist named Julius Jordan was excavating Uruk, on the banks of the Euphrates in what is now Iraq. Five thousand years ago, Uruk – with a population of several thousand people – would have been one of the great cities of the age.

‘He built the town wall of Uruk, city of sheepfolds,’ proclaims the Epic of Gilgamesh, one of the earliest works of literature. ‘Look at its wall with its frieze like bronze! Gaze at its bastions, which none can equal!’

And this 5,000-year-old metropolis presented Julius Jordan with two puzzles. The first was a treasure trove: a library of clay tablets, far older than any previous examples of writing. Their script, which became known as ‘cuneiform’, was abstract.Nobody could make any sense of it.

The second puzzle was that Uruk and other Mesopotamian cities were sprinkled with small clay baubles in varying shapes: cones, spheres, cylinders, even a suppository-style lozenge. What were they for? Nobody knew, although Julius Jordan, no fool, noted that they reminded him of ‘the commodities of daily life: jars, loaves and animals’.

It took more four decades before anyone made much progress on Julius Jordan’s mystery. The breakthrough came courtesy of a French archaeologist, Denise Schmandt-Besserat, who had been cataloguing appearances of these tokens from Pakistan to Turkey. And she had a theory: the clay pieces were tokens, and their purpose was to help people count.

The method Schmandt-Besserat described is called ‘correspondence counting’. It’s counting for people who lack numbers: all you need to do with correspondence counting is to look at two quantities and verify that they’re the same. So if you wanted to count – say – 12 loaves of bread, you could do that by checking them against 12 loaf-shaped counters. Nineteen jars of olive oil could be counted using 19 jar-shaped tokens.

Correspondence counting is ancient. The Ishango Bone, found in central Africa, shows tally-marks on the thigh bone of a baboon. It seems to be designed for correspondence counting and it is 200 centuries old. But the Uruk tokens were a big step forward from the Ishango Bone, because they could be used to keep track of several different quantities – and also to perform the simple mathematical operations of adding and subtracting.

This was essential, because Uruk was a great city. Such cities required specialists – craftsmen, priests, soldiers, arable and livestock farmers. There were harvests to coordinate, construction projects to manage, trading, taxation, and planning. Schmandt-Besserat was inviting us to picture hard-working nerds at the door of the temple or the government storehouse, using tokens to count as the sheep, jars of wine and sacks of grain entered and left. These people were the world’s first accountants.

But then what about Julius Jordan’s first mystery – the ubiquitous, indecipherable cuneiform clay tablets? Schmandt-Besserat had a solution for that as well: she noticed that the apparently-abstract symbols on the cuneiform tablets weren’t as abstract as they seemed: they resembled the tokens.

Everyone had missed this point because of the different layers of symbolism involved. First the tokens were used to represent oxen or jars of honey, and to track the back-and-forth. Then the tablets had been used to make a more permanent record: pressing the hard-baked tokens into the wet clay of the tablet. And then at some stage, some ancient accountant decided that an all-purpose writing tool like a stylus could be used instead. These layers of abstraction – a commodity represented by a token represented by a written imitation of the impression of the token – had hidden the fact that, deep down, the cuneiform had once been pictures of commodities. The world’s first writing wasn’t being used to compose poetry or send orders to distant armies – it was used for the world’s first written accounts.

And since it is a small step from a record of payment to a record of debt, writing was soon to produce contracts, too. One clever trick was called a bulla – a hollow clay ball. On the outside was a contract written in cuneiform; on the inside were the tokens that represented the deal. The inside and the outside matched up, verifying each other.

It wasn’t long before the ancient accountants of Uruk gave us another world-changing idea: an abstract number system. Rather than recording ten goats as ten separate goat indentations, use a symbol for ‘ten’ (it was a circle). Quick on the heels of that came the first calculations of compound interest.

In the modern world, most major financial transactions (and many minor ones) are based on an abstract number system and explicit written contracts: insurance, shares, mortgages and bank accounts depend on the ability to write things down. These contracts – from the bullas of Mesopotamia to the sophisticated financial instruments of 21st-century Wall Street – are fundamental to a complex society. It simply wouldn’t be possible to organise city life without the ability to write receipts, purchase orders, debt contracts and tax demands.

The citizens of Uruk could boast a remarkable set of achievements: the first accounts, the first contracts, the first debts with compound interest, the first mathematics and the first writing. But as the cliché goes, necessity had been the mother of invention: without these tools it would have been overwhelming to run a sophisticated economy, dealing with a web of interdependencies between people who may never even meet. Writing was no gift from baboon-faced Thoth. It was a tool for getting an economy organised, and it was developed by the world’s first accountants.

Tim Harford is a Financial Times columnist. His new book is Fifty Things That Made The Modern Economy (Little, Brown), also published in the US as  Fifty Inventions That Shaped The Modern Economy.