Short answer
Yes, for a medical reason, such as before chemotherapy, as long as the sperm is used only by the man with his own wife while their marriage lasts. It may never be given to anyone else, and it may not be used after divorce or his death. Clinics must be trusted to prevent any mix-up. Ask a mufti, especially if you are not yet married.
Storing a husband's sperm for later treatment with his wife is permissible where there is a need, with strict safeguards. Using it after the marriage ends, by divorce or death, or for any woman other than his wife, is haram.
The four schools agree on this.
Explanation
Treatments such as chemotherapy, radiotherapy and some surgeries can damage fertility. Doctors often offer to freeze sperm first so that the man can still have children later through IUI or IVF. Allah gives children to whom He wills, and seeking a lawful way to keep that door open is part of seeking treatment.
Conditions scholars set:
- the sperm is used only to conceive with the man's own wife
- it is used only while their marriage lasts; after a divorce, or once the husband has died, the marriage has ended and the sperm must not be used
- it is never donated, sold or used for another couple (see donor sperm and eggs)
- the clinic is reliable and labels and stores samples carefully
- you instruct the clinic in writing to destroy the samples if you die or divorce
Producing the sample. Masturbation is normally not allowed, but many muftis permit it for a genuine medical need such as this. A married man is better helped by his wife. See masturbation.
If you are not married yet. Freezing sperm before cancer treatment so that you can have children with a future wife is a newer question. Many scholars allow it because of the need, with the same conditions once you marry, but ask a mufti about your case.
For women, see egg freezing, and for the main rules of fertility treatment, is IVF haram. Follow a qualified doctor's advice on timing.
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-Baqara 2:223
نِسَآؤُكُمْ حَرْثٌۭ لَّكُمْ فَأْتُوا۟ حَرْثَكُمْ أَنَّىٰ شِئْتُمْ ۖ وَقَدِّمُوا۟ لِأَنفُسِكُمْ ۚ وَٱتَّقُوا۟ ٱللَّهَ وَٱعْلَمُوٓا۟ أَنَّكُم مُّلَٰقُوهُ ۗ وَبَشِّرِ ٱلْمُؤْمِنِينَ ﴿٢٢٣﴾
Your wives are a place of sowing of seed for you, so come to your place of cultivation however you wish and put forth [righteousness] for yourselves. And fear Allah and know that you will meet Him. And give good tidings to the believers.
A husband's seed belongs only within his marriage.
Quran, Surah Ash-Shura 42:49-50
لِّلَّهِ مُلْكُ ٱلسَّمَٰوَٰتِ وَٱلْأَرْضِ ۚ يَخْلُقُ مَا يَشَآءُ ۚ يَهَبُ لِمَن يَشَآءُ إِنَٰثًۭا وَيَهَبُ لِمَن يَشَآءُ ٱلذُّكُورَ ﴿٤٩﴾ أَوْ يُزَوِّجُهُمْ ذُكْرَانًۭا وَإِنَٰثًۭا ۖ وَيَجْعَلُ مَن يَشَآءُ عَقِيمًا ۚ إِنَّهُۥ عَلِيمٌۭ قَدِيرٌۭ ﴿٥٠﴾
To Allah belongs the dominion of the heavens and the earth; He creates what he wills. He gives to whom He wills female [children], and He gives to whom He wills males. Or He makes them [both] males and females, and He renders whom He wills barren. Indeed, He is Knowing and Competent.
Children are Allah's gift, and lawful means may be used in seeking them.
Sahih al-Bukhari 5678
Sahih... ما أنزل الله داء إلا أنزل له شفاء ...
"Allah has not sent down any disease without sending down a cure for it."
Protecting fertility is part of lawful treatment.
Sahih Muslim 2204
Sahih... لكل داء دواء فإذا أصيب دواء الداء برأ بإذن الله ...
"Every disease has a remedy, and when the right remedy is found, the disease is cured by Allah's permission."
Medical means are used while trusting Allah for the result.
Where the ruling is recorded
- Resolutions of the Islamic Fiqh Academy (OIC), Resolution on test-tube babies. Only the husband's sperm and the wife's egg, during their marriage, may be used.
- Jadid Fiqhi Masa'il (Khalid Saifullah Rahmani), Chapter on test-tube babies. A Hanafi treatment of fertility treatment that forbids any third party.
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.