The Messenger of Allah ﷺ, who is the truthful and the trusted, narrated to us, "Each one of you has his creation gathered in his mother's womb for forty days, then he becomes a clinging clot for a similar period, then he becomes a lump of flesh for a similar period. Then Allah sends to him the angel, who breathes the soul into him and is commanded with four matters, to record his sustenance, his lifespan, his deeds, and whether he will be wretched or blessed.By the One besides whom there is no god, one of you may perform the deeds of the people of Paradise until there is only an arm's length between him and it, then what has been written overtakes him, so he ends with the deeds of the people of the Fire and enters it. And one of you may perform the deeds of the people of the Fire until there is only an arm's length between him and it, then what has been written overtakes him, so he ends with the deeds of the people of Paradise and enters it."
حدثنا هناد حدثنا أبو معاوية عن الأعمش عن زيد بن وهب
حدثنا رسول الله ﷺ وهو الصادق المصدوق إن أحدكم يجمع خلقه في بطن أمه في أربعين يوما ثم يكون علقة مثل ذلك ثم يكون مضغة مثل ذلك ثم يرسل الله إليه الملك فينفخ فيه الروح ويؤمر بأربع يكتب رزقه وأجله وعمله وشقي أو سعيد فوالذي لا إله غيره إن أحدكم ليعمل بعمل أهل الجنة حتى ما يكون بينه وبينها إلا ذراع ثم يسبق عليه الكتاب فيختم له بعمل أهل النار فيدخلها وإن أحدكم ليعمل بعمل أهل النار حتى ما يكون بينه وبينها إلا ذراع ثم يسبق عليه الكتاب فيختم له بعمل أهل الجنة فيدخلها
Agreed upon (by Bukhari and Muslim). Muslim also reported it in the Book of Divine Decree, chapter on how the human being is created in his mother's womb, etc., hadith no. 2643, from the hadith of Abu Muawiya, and Bukhari, hadith no. 6594, from Amash through the same route.There is also a report on this subject from Abu Hurairah [Muslim, no. 2651] and Anas [Bukhari, no. 6595, and Muslim, no. 2646].Ahmad's statement is sahih from him.