Sahih al-Bukhari 3208
Hasan bin Rabi' narrated to us that Abul Ahwas (Sallam bin Sulaim) told us. He narrated from A'mash, A'mash from Zaid bin Wahb that Hazrat Abdullah (bin Mas'ud (ra)) said: The Messenger of Allah (saw) told us, and he (saw) is truthful, and what was told to him (saw) is also true. He (saw) said: “The elements of the creation of each of you are gathered in his mother's womb for forty days. Then after that he remains in the state of a clinging clot ('alaqah) for forty days. Then after that he remains in the state of a lump of flesh (mudghah) for forty days. Then after that Allah sends an angel who is commanded to write four things, and he is told: Write down his deeds and his provision {and his lifespan}, and write also whether he will be wretched or fortunate. Then after that the soul is breathed into him. That is why one of you keeps doing good deeds until, when there remains between him and Paradise a distance of only an arm's length, his destiny overtakes him and he begins to do the deeds of the people of Hell. And likewise one keeps doing evil deeds until, when there remains between him and the Fire a distance of only an arm's length, his destiny overtakes him and he begins to do the deeds of the people of Paradise.”
AI-translated by Islam-Today