Many hadith were written in the Prophet's own lifetime — 'Abdullah ibn 'Amr recorded what he heard in a sheet known as as-Sahifa as-Sadiqa, and the Prophet ordered a sermon written out for a Yemeni man named Abu Shah (Sahih al-Bukhari). Broad official compilation was later commanded by the caliph 'Umar ibn 'Abd al-'Aziz, who instructed scholars such as Ibn Shihab az-Zuhri to gather the Sunnah for fear of its loss; the great sorted collections of al-Bukhari, Muslim, and others followed in the third century. Alongside writing, the Companions and their students preserved hadith through disciplined memorization, and Allah's promise, "Indeed, We sent down the Reminder and We will be its guardian" (15:9), is understood by the scholars to safeguard the Sunnah that explains the Quran (16:44).
Q&A · Hadith
When were the hadith first written down and compiled?
Evidence — the daleel
On deen2u
Informational, not a personal fatwa. Consult a qualified scholar for rulings on your situation.