The short answer
Writing developed over several thousand years. It began with counting and simple picture marks and eventually reached scripts that could record full spoken languages. The earliest writing we can identify comes from southern Mesopotamia, around 3300 BCE, though the exact date is debated. Egyptian hieroglyphs appeared at about the same time or later, and writing developed in other places separately.
What is the most ancient way of communication?
Spoken language, by a long way. People talked for a very long time before anyone wrote anything down. Writing is a way of recording language in a form that lasts, and much of its importance comes from that lasting quality.
Counting before writing
Before the first writing, people kept track of goods in other ways. The archaeologist Denise Schmandt-Besserat proposed that small clay tokens, used to represent goods and amounts, were sometimes sealed inside clay envelopes. Impressions of the tokens on the outside of the envelopes may have been a step toward writing.
Her idea has been influential, but critics note that it is hard to show a direct line from these tokens to cuneiform. The debate is still open.
The first tablets
Around 3300 BCE, scribes at Uruk in southern Mesopotamia began to use signs on clay tablets. Most early tablets are accounts: lists of grain, livestock and other goods. Numbers were written as separate marks beside the items they counted.
From pictures to sounds
The early signs mostly stood for things. Over time, some signs came to stand for sounds, so a sign could be used for a word that sounded like the name of the object it showed. By the middle of the third millennium BCE, scribes were using this principle widely. That made it possible to write names and more abstract words, and it is what allowed cuneiform to record a full language.
How writing spread
Cuneiform was first used for Sumerian, then adapted for Akkadian and for languages such as Hittite and Elamite. Writing moved along trade routes and through conquest, and each culture adapted it to its own speech. At Ugarit, in what is now Syria, scribes wrote an alphabet of about thirty signs in cuneiform. It was not the ancestor of the alphabets used today.
Other early scripts
Egyptian hieroglyphs, Chinese characters and the writing of Mesoamerica all developed separately and at different times. The Indus script of South Asia remains undeciphered. Each has its own history, and none should be treated as a simple copy of another.
Why the history is hard to pin down
Dates for early writing are debated because they depend on excavated layers, comparisons between sites and changing views of how those sites relate. Much of what was written has not survived. Clay lasts when it is baked, and many tablets survived because fires hardened them. Many more were lost to erosion, looting and later building.
When did we start keeping history?
The answer depends on what you count as history. Writing gives us the earliest records that historians can read directly. Before written records, the period of unrecorded history is known as prehistory, and historians study it through other kinds of evidence, such as tools, bones, pottery and buildings.