From the route of Abu ^Abdir-Rahman ^Abdillah bin Mas^ud, may Allah accept his deeds, who said: The Messenger of Allah, sallallahu ^alayhi wa sallam, told us and he is the Truthful One and the one to whom the truth is told:
<<The appearance of the one of you would be completed in ones mother’s womb for forty days as a Nutfah (joined fertilized sperm.) Then for a similar duration would be as an ^Alaqah (bloody clot.)
Then for a similar duration would be as a Mudghah (a piece of flesh.) Then the Angel would be sent to blow the soul into it, and would be ordered to write down four matters: ones sustenance, death time, deeds, and whether one would die a blasphemer or a believer.
I swear by Allah, the One whom no one is God but Him, the one of you would perform the deeds that appear to be the deeds of the People of Paradise until a cubit separates one from entering it, then what is written in the Guarded Tablet happens and one would do the deeds of the People of Hellfire, and would enter it. And one of you would perform the deeds of the People of Hellfire until a cubit separates one from entering it, then what is written in the Guarded Tablet happens and one would do the deeds of the People of Paradise, and would enter it.>>
Narrated by al-Bukhari and Muslim.