It is narrated from Sayyiduna Abdullah (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him), the truthful and the one confirmed as truthful, said: "The creation of each of you is gathered in his mother's womb for forty days; then it becomes a clinging clot in the same way; then it becomes a lump of bones and flesh in the same way. Then Allah Almighty sends the angel, who breathes his soul into him. Then he is commanded with four words: to write his provision, his deeds, his term of life, and (whether) he will be fortunate or wretched. By the One besides whom there is no god! One of you does the deeds of the people of Hell until there remains between him and Hell only an arm's length; then the decree overtakes him, his end is sealed with the deeds of the people of Paradise, and he enters it. And one of you does the deeds of the people of Paradise until there remains between him and Paradise only an arm's length; then the decree overtakes him, his end is sealed with the deeds of the people of Hell, and he enters Hell."
Imam Muslim recorded it.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب العدد / 15421