Short answer
According to a sahih hadith, the soul (ruh) is breathed into the fetus after stages of forty days each, which most scholars understood as 120 days after conception, about four months. Before that the embryo is living, growing tissue, but the soul has not yet been placed in it. What the soul really is, only Allah knows.
The majority of Hanafi and other scholars hold that ensoulment happens at 120 days, based on the hadith of Ibn Mas'ud. This affects rulings: abortion after ensoulment is like taking a life, while before it Hanafi scholars allow it only for a valid reason, and it is still not taken lightly.
The four schools agree on this.
Explanation
The Prophet ﷺ said that each of you is gathered in his mother's womb for forty days, then becomes a clinging clot for a like period, then a lump of flesh for a like period. Then Allah sends an angel who is commanded to write four things: his deeds, his provision, his lifespan, and whether he will be wretched or happy. "Then the soul is breathed into him." Most scholars read the three periods as 120 days in all.
The Quran describes the same stages: "We made the sperm-drop into a clinging clot, and We made the clot into a lump [of flesh], and We made [from] the lump, bones, and We covered the bones with flesh; then We developed him into another creation" (23:14). Many commentators said "another creation" refers to the breathing in of the soul. Some contemporary scholars, citing another hadith in Sahih Muslim about forty days, discuss whether some stages come earlier; the 120-day view remains the main one in the Hanafi school.
As for the soul itself, the Quran says: "The soul is of the affair of my Lord. And mankind have not been given of knowledge except a little" (17:85). Muslims do not claim to measure it. The ruling question most people ask is about abortion, which depends on the stage and the reason; read does Islam allow abortion? and ask a mufti about a specific case.
See also what happens after you die?, when the soul leaves the body.
Ask a mufti about your own case. This answer explains the general ruling. When the details of your situation matter, as they do here, ask a qualified mufti and give them the full facts. Where to ask a scholar.
The evidence
Quran, Surah Al-Muminoon 23:14
ثُمَّ خَلَقْنَا ٱلنُّطْفَةَ عَلَقَةًۭ فَخَلَقْنَا ٱلْعَلَقَةَ مُضْغَةًۭ فَخَلَقْنَا ٱلْمُضْغَةَ عِظَٰمًۭا فَكَسَوْنَا ٱلْعِظَٰمَ لَحْمًۭا ثُمَّ أَنشَأْنَٰهُ خَلْقًا ءَاخَرَ ۚ فَتَبَارَكَ ٱللَّهُ أَحْسَنُ ٱلْخَٰلِقِينَ ﴿١٤﴾
Then We made the sperm-drop into a clinging clot, and We made the clot into a lump [of flesh], and We made [from] the lump, bones, and We covered the bones with flesh; then We developed him into another creation. So blessed is Allah, the best of creators.
Describes the stages of the fetus.
Quran, Surah Al-Israa 17:85
وَيَسْـَٔلُونَكَ عَنِ ٱلرُّوحِ ۖ قُلِ ٱلرُّوحُ مِنْ أَمْرِ رَبِّى وَمَآ أُوتِيتُم مِّنَ ٱلْعِلْمِ إِلَّا قَلِيلًۭا ﴿٨٥﴾
And they ask you, [O Muhammad], about the soul. Say, "The soul is of the affair of my Lord. And mankind have not been given of knowledge except a little."
Shows the reality of the soul is known to Allah.
Sahih al-Bukhari 3208
Sahih... وَشَقِيٌّ أَوْ سَعِيدٌ. ثُمَّ يُنْفَخُ فِيهِ الرُّوحُ ...
"And whether he will be wretched or happy. Then the soul is breathed into him."
Places ensoulment after the three stages of forty days.
Where the ruling is recorded
- Fath al-Bari (Ibn Hajar), Book of the beginning of creation, the hadith of Ibn Mas'ud. Discusses the stages and the timing of ensoulment.
- Radd al-Muhtar (Ibn Abidin), Book of marriage, the discussion of azl and of aborting a pregnancy before the soul is breathed in. Sets out the Hanafi ruling that depends on ensoulment at 120 days.
Checked by our team. For a more accurate answer to your own situation, consult a scholar. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.