The Quran was revealed from Allah to the Prophet Muhammad (PBUH) by way of the ArchAngel Gabriel, in a most unique fashion, spanning over years, from 610-632ce. Each time verses were revealed, there were numerous proficient skilled dedicated scribes ready to commit the scripture to writing. It would also clarify the order of each chapter or verse in the Quran. At the same time, any of the companions committed every verse to memory, and would recite them to the Prophet (PBUH) directly, as well as review amongst each other, teach others, and of course recite in prayer throughout the course of every morning, afternoon, and especially evening.
Upon the Prophets passing, in 632 ce, the first Caliph of Islam, Abu Bakr, ordered the most proficient of Quran memories to gather the entire Quran into a single book form, verifying every single letter of every word of every verse of every chapter multiple times over for accuracy. One of the head Quran memorizers tasked with this project famously commented
“If I had been tasked with moving Mount Uhud, it would have been less tedious than what I was tasked with…”
The task was completed successfully, then that written register of the complete Quran was secured by the Caliphs, for safekeeping. But remember, the Quran continued to spread verbally, through memorization by heart, prayer, learning, and teaching.
Over the next 15 years, as Islam spread throughout all of the surrounding continents, many people entered into this way of life who were neither Arab, nor proficient in the Arabic language. As they began to memorise the Quran, the need became apparent for a unified written Quran source for the rapidly growing Muslim population.
At this time, the presiding third Caliph, Uthman Bin Affaan, retrieved the preserved written Quran register, and ordered a copy be made and sent to every Islamic province, to be used as an official uniform Quran reference. Also, each province began awarding certificates and kept a written register, including chains of teachers linking back to the most proficient Quran memorizers of the Prophet's time, who learned directly from the Prophet himself. In this way, the integrity of each word of the original Quranic text has been perfectly preserved.