The Messenger of Allah ﷺ, the truthful and trustworthy, told 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 the angel is sent to him, who breathes the soul into him and is commanded to record four matters, his provision, 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 do the deeds of the people of Paradise until there is only an arm's length between him and it, then what is written overtakes him, and he ends with the deeds of the people of the Fire and enters it. And a man may do the deeds of the people of the Fire until there is only an arm's length between him and it, then what is written overtakes him, and he ends with the deeds of the people of Paradise and enters it."
حدثنا أبو معاوية حدثنا الأعمش عن زيد بن وهب
حدثنا رسول الله ﷺ وهو الصادق المصدق إن أحدكم يجمع خلقه في بطن أمه في أربعين يوما ثم يكون علقة مثل ذلك ثم يكون مضغة مثل ذلك ثم يرسل إليه الملك فينفخ فيه الروح ويؤمر بأربع كلمات رزقه وأجله وعمله وشقي أم سعيد فوالذي لا إله غيره إن أحدكم ليعمل بعمل أهل الجنة حتى ما يكون بينه وبينها إلا ذراع فيسبق عليه الكتاب فيختم له بعمل أهل النار فيدخلها وإن الرجل ليعمل بعمل أهل النار حتى ما يكون بينه وبينها إلا ذراع فيسبق عليه الكتاب فيختم له بعمل أهل الجنة فيدخلها
Its chain of transmission is sahih. It was narrated by Bukhari and Muslim, Abu Dawud, Tirmidhi, and Ibn Majah, as noted in Dhakhair Mawarith 4723. It is the fourth hadith of the Forty Hadith of Nawawi. Ibn Rajab said in 33, "This hadith is agreed upon as sahih, and the ummah has accepted it." See also 3553.