Istimna

Scholars of Sunni Islam generally do not approve of masturbation, except in extenuating circumstances. They encourage Muslims to fast to reduce sexual desire if they cannot marry,[4] as this was the recommendation of the Prophet.

Yet if one's desire is so overwhelming one might perform masturbation but in that case it will be like eating the flesh of a pig to survive from major hunger or starvation when no other food is available.[5]

Masturbation, like any form of sex in which seminal or vaginal fluids have been released, breaks one's fast if performed during the daylight hours and requires a major ablution if any seminal or vaginal fluids were released.

According to Sheikh Hamed Al-Ali: "Masturbation during the daytime of Ramadan breaks the fast, based on the Hadith that a fasting Muslim gives up eating, drinking, and sexual desire for the sake of Allah. Since masturbation is a kind of sexual desire, a fasting Muslim must avoid it. Therefore, masturbation invalidates the fast as does food and as it is one of the sins that if someone does it he or she would be violating the sanctity of this month."

Sunni view

Masturbation (for both men and women) is haraam (forbidden) in Islam based on the following evidence:
First from the Qur’aan:
Imam Shafi’i stated that masturbation is forbidden based on the following verses from the Qur’aan (interpretation of the meaning):
"And those who guard their chastity (i.e. private parts, from illegal sexual acts). Except from their wives or (the captives and slaves) that their right hands possess, - for them, they are free from blame. But whoever seeks beyond that, then those are the transgressors." 23.5-7 Here the verses are clear in forbidding all illegal sexual acts (including masturbation) except for the wives or that their right hand possess. And whoever seeks beyond that is the transgressor. The four Sunni schools of jurisprudence (known as Madhaahib - the Hanafi, Shafi'i, Maliki and Hanbali schools of Fiqh) have differing stances on the issue. Some see it forbidden in certain cases (i.e. if it leads a man/woman to ignore their spouse sexually) but recommended it when they see it as a lesser evil to illicit sex. It is generally prohibited according to the Hanafi and Hanbali Mazhabs, unless one fears adultery or fornication, or is under the desire pressure, in which case, it is permissible to seek a relief through masturbation. It is prohibited all the time according to the Maliki and Shafi`i Mazhabs.[7] However, Imam Ibn Hazm regard masturbation as permissible.[8]

Scholars have also stated that masturbation would not be necessary if one realizes the flexible approach Islam takes to marriage. For example, according to Sheikh Shomeh Yerkity, 'against the clear teachings of Islam, marriage has been rendered another difficult process today due to warped customs and conventions and undue expectations. When we approach marriage from the point of view of pristine Islam, we shall find less and fewer people being forced to exercise the above type of exceptional rulings'.[5]

Shi'a view

Any sexual engagement outside of marriage including masturbation is a major sin altogether in the Shi'a Islam. Extra-marital sexual engagement causes the doer to be punished in this life and in the afterlife (Qiyama). The Qur'an says, "The believers are those who protect their sexual organs except from their spouses... Therefore, whosoever seeks more beyond that (in sexual gratification), then they are the transgressors." (23:5-6) [9] and it is not allowed in any situation.

In case of living abroad without wives or inability of regular marriage, Quran permits Mutah, a contract marriage system through mutual understanding. It is mentioned, "But let them who find not [the means for] marriage abstain [from sexual relations] until Allah enriches them from His bounty. And those who seek a contract [for eventual emancipation] from among whom your right hands possess - then make a contract with them if you know there is within them goodness and give them from the wealth of Allah which He has given you. And do not compel your slave girls to prostitution, if they desire chastity, to seek [thereby] the temporary interests of worldly life. And if someone should compel them, then indeed, Allah is [to them], after their compulsion, Forgiving and Merciful." (Qur'an, 24:33)

If the situation is not favorable for performing both regular and contract marriage, Shi'ite jurisprudence suggests to perform fasting to restrain sexual desire.