Abdullah bin Masud reported,

The Messenger of Allah ﷺ, the truthful and trustworthy, told us that the creation of each one of you is gathered in his mother's womb for forty days or forty nights, then becomes a clinging clot for a like period, then becomes a lump of flesh for a like period. Then the angel is sent to him and is permitted to record four matters. He writes down his provision, his lifespan, his deeds, and whether he will be wretched or blessed. Then the soul is breathed into him.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 performs 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 performs the deeds of the people of Paradise and enters it.

Bukhari 7454

Sahih

حدثنا آدم حدثنا شعبة حدثنا الأعمش سمعت زيد بن وهب سمعت

عبد الله بن مسعود رضي الله عنه

حدثنا رسول الله ﷺ وهو الصادق المصدوق أن خلق أحدكم يجمع في بطن أمه أربعين يوما أو أربعين ليلة ثم يكون علقة مثله ثم يكون مضغة مثله ثم يبعث إليه الملك فيؤذن بأربع كلمات فيكتب رزقه وأجله وعمله وشقي أم سعيد ثم ينفخ فيه الروح فإن أحدكم ليعمل بعمل أهل الجنة حتى لا يكون بينها وبينه إلا ذراع فيسبق عليه الكتاب فيعمل بعمل أهل النار فيدخل النار وإن أحدكم ليعمل بعمل أهل النار حتى ما يكون بينها وبينه إلا ذراع فيسبق عليه الكتاب فيعمل عمل أهل الجنة فيدخلها

البخاري 7454صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Tawhid
Chapter
His saying, "And Our word has already preceded for Our servants, the messengers"
Numbering
Darussalam 7454
Bukhari 7454