‘Abdullāh ibn Mas‘ūd (may Allah be pleased with him) reported: The Messenger of Allah (may Allah’s peace and blessings be upon him) related to us, and he is the truthful and the trusted one; he said:"The creation of each one of you is brought together in his mother's womb for forty days as a sperm-drop. Then he becomes a clinging clot for a similar period, then a lump (of flesh) for a similar period, then there is sent to him the angel who blows his soul into him and who is commanded to write down four things: his sustenance, lifespan, actions, and whether miserable or happy. By Allah other than Whom there is no god, one of you would do the actions of the people of Paradise until there is an arm's length (cubit) between him and Paradise, but the predestination overtakes him, causing him to do actions of the people of Hellfire, and he enters it; and one of you would do the actions of the people of Hellfire until he is an arm's length away from Hellfire, but the predestination overtakes him, causing him to do deeds of the people of Paradise, and he enters it." Sahih/Authentic. - [Al-Bukhari and Muslim]
Ibn Mas‘ūd reported: The Messenger of Allah (may Allah be pleased with him) related to us - and he is the truthful in what he says and the revelation he receives and the one to whom Allah has fulfilled His promise. He said: The creation of each one of you is brought together. This is because when a man engages in sexual intercourse with his wife, the dispersed semen comes together. The Hadīth does not mention how this happens. It is collected in his mother's womb for forty days in the form of a drop. Then, he becomes a clot of blood, in the following forty days, given his words "for a similar period". Then, he becomes a lump (of flesh), in the third forty-day period. Thereafter, Allah sends him the angel, who breathes life into him after the end of the third period of forty days. The angel will then be commanded to write down four things: his sustenance, which the amount of blessings he will get during his lifetime; his lifespan, which is the duration of his existence in the world; his deeds; and whether miserable or happy. All this is determined in accordance with Allah's wisdom and predestination. Then, the Prophet (may Allah’s peace and blessings be upon him) swears that a person might do the deeds of the dwellers of Paradise, and his deeds appear to be good in the eyes of people, as indicated in another version of this Hadīth. He proceeds like this until there is only an arm's length between him and Paradise, an example to indicate closeness. But then his predestination overcomes him and he performs the deeds of the dwellers of Hellfire and his life ends in this state and he enters Hellfire. This is because it is required for a person's good deeds to be accepted that he remains steadfast and does not change his course. And he speaks about another person who performs bad deeds of the dwellers of Hellfire until he is close to entering it, as if only an arm's length is separating him from it, but his predestination overcomes him and he performs the deeds of the dwellers of Paradise and enters it - out of Allah's grace and bounty.
The Hadīth points out the Companions' firm belief and great respect for the Prophet (may Allah’s peace and blessings be upon him).
It shows Allah's power and favors so that His servants should be grateful to Him, as He makes them go through these stages until they turn into human beings endowed with pleasant appearances, minds, and good understanding.
The outcome of things goes in the course determined by the divine decree and predestination.
It alerts people to the perfect power of Allah Almighty and His ability to gather and resurrect all creation. If He is able to create people from semen and then a clot of blood and then a lump of flesh that is prepared to receive the breathing of life, He is also able to restore them after turning into dust and breathe life into them again and gather them on the Day of Resurrection for the reckoning and recompense.
Angels are assigned with different actions and tasks.