It is narrated from Sayyiduna Abdullah bin Mas'ud (may Allah be pleased with him) that the Prophet (peace and blessings be upon him) said: "The sperm-drop remains in the womb for forty days, then for a similar period it is an alaqah (a clinging clot), then for a similar period it is a mudghah (a lump of flesh). Then Allah Almighty sends the angel with four matters, and he writes down his provision, his term of life, and whether he is wretched or fortunate."
Then the Messenger of Allah (peace and blessings be upon him) said: "One of you does the deeds of the people of Paradise until there is only a forearm's length between him and Paradise; then the writing (decree) that was written beforehand overtakes him, and he does the deeds of the people of Hell until he dies. And one of you does the deeds of the people of Hell until there is only a forearm's length between him and it; then the writing (decree) that was written beforehand overtakes him, and he does the deeds of the people of Paradise before he dies."
Hadith Referenceالمعجم الكبير للطبراني / باب العين / 10402