Language:
كتاب أحاديث الأنبياء
60  
Prophets
(1)
Chapter: The creation of Adam and his offspring
(1)
بَابُ خَلْقِ آدَمَ صَلَوَاتُ اللَّهِ عَلَيْهِ وَذُرِّيَّتِهِ
Sahih al-Bukhari 3332

Narrated `Abdullah:

Allah's Messenger (ﷺ), the true and truly inspired said, "(as regards your creation), every one of you is collected in the womb of his mother for the first forty days, and then he becomes a clot for another forty days, and then a piece of flesh for another forty days. Then Allah sends an angel to write four items: He writes his deeds, time of his death, means of his livelihood, and whether he will be wretched or blessed (in religion). Then the soul is breathed into his body. So a man may do deeds characteristic of the people of the (Hell) Fire, so much so that there is only the distance of a cubit between him and it, and then what has been written (by the angel) surpasses, and so he starts doing deeds characteristic of the people of Paradise and enters Paradise. Similarly, a person may do deeds characteristic of the people of Paradise, so much so that there is only the distance of a cubit between him and it, and then what has been written (by the angel) surpasses, and he starts doing deeds of the people of the (Hell) Fire and enters the (Hell) Fire."

حَدَّثَنَا عُمَرُ بْنُ حَفْصٍ، حَدَّثَنَا أَبِي، حَدَّثَنَا الأَعْمَشُ، حَدَّثَنَا زَيْدُ بْنُ وَهْبٍ، حَدَّثَنَا عَبْدُ اللَّهِ، حَدَّثَنَا رَسُولُ اللَّهِ صلى الله عليه وسلم وَهْوَ الصَّادِقُ الْمَصْدُوقُ ‏ "‏ إِنَّ أَحَدَكُمْ يُجْمَعُ فِي بَطْنِ أُمِّهِ أَرْبَعِينَ يَوْمًا، ثُمَّ يَكُونُ عَلَقَةً مِثْلَ ذَلِكَ، ثُمَّ يَكُونُ مُضْغَةً مِثْلَ ذَلِكَ، ثُمَّ يَبْعَثُ اللَّهُ إِلَيْهِ مَلَكًا بِأَرْبَعِ كَلِمَاتٍ، فَيُكْتَبُ عَمَلُهُ وَأَجَلُهُ وَرِزْقُهُ وَشَقِيٌّ أَوْ سَعِيدٌ، ثُمَّ يُنْفَخُ فِيهِ الرُّوحُ، فَإِنَّ الرَّجُلَ لَيَعْمَلُ بِعَمَلِ أَهْلِ النَّارِ حَتَّى مَا يَكُونُ بَيْنَهُ وَبَيْنَهَا إِلاَّ ذِرَاعٌ، فَيَسْبِقُ عَلَيْهِ الْكِتَابُ فَيَعْمَلُ بِعَمَلِ أَهْلِ الْجَنَّةِ، فَيَدْخُلُ الْجَنَّةَ، وَإِنَّ الرَّجُلَ لَيَعْمَلُ بِعَمَلِ أَهْلِ الْجَنَّةِ، حَتَّى مَا يَكُونُ بَيْنَهُ وَبَيْنَهَا إِلاَّ ذِرَاعٌ فَيَسْبِقُ عَلَيْهِ الْكِتَابُ، فَيَعْمَلُ بِعَمَلِ أَهْلِ النَّارِ فَيَدْخُلُ النَّارَ ‏"‏‏.‏
Reference : Sahih al-Bukhari 3332
In-book reference : Book 60, Hadith 7
USC-MSA web (English) reference : Vol. 4, Book 55, Hadith 549
  (deprecated numbering scheme)