The Ruling on Masturbation: Prohibitively Disliked & Sinful
                           
                           
Masturbation is sinful, being prohibitively disliked, because of its
                           many personal and societal ill-effects that are known and recognised in sane traditional societies and by balanced people
                           the world over. 
                           
As for modern 'expert' opinions that there is 'nothing wrong with
                           it,' these are the opinions of the same people who see nothing wrong with fornication, nudity, and most other personal and
                           social depravity. 
                           
The early Muslims used to say, "The one who weds his hand is accursed."
                           (Fath al-Qadir) 
                           
Its prohibition was established by Allah Most High's words, "Those
                           who guard their private parts, except from their spouses..." [Qur'an, 23: 5] 
                           
Thus, the general ruling regarding sexual activity is that it is impermissible,
                           except through the particular channel that Allah permitted, out of His tremendous wisdom and mercy for His creation.
                           
                           
The rulings of the Shariah are for the worldly and eternal benefit
                           of humanity, as a manifestation of the tremendous mercy of Allah, for Allah Himself is absolutely free of any need. Rather,
                           it is we who need guidance, to give true joy and illumination to our lives in this world and the next. 
                           
So, When Could Masturbation Possibly Be Allowed? 
                           
Masturbation is only allowed in the very rare situation where:
                           
  
                           
                           - if the person did not do this, they genuinely fear that they would
                           fall into actual zina (i.e. unlawful sexual intercourse), because of their uncontrollable desire, and 
                           
- they are unable to marry, and 
                           
- have taken all reasonable means to lessen their passion (such as
                           fasting, lowering their gaze, avoiding meat and dairy products, avoiing those things that stir their desires, such as bad
                           company, spending unnecessary time outdoors, especially in public places such as shopping malls where there is fitna, avoiding
                           watching tv and surfing the internet, etc). 
In such cases, it is not haram because of the principle that,
                           "If there are only two options, but harmful, then one takes the lesser of the two harms to avoid the greater one."
                           
                           
However, when there are third options, it remains impermissible to
                           take the lesser harm, such as masturbation. 
                           
Even when the conditions outlined above are met, it would only not
                           be impermissible to the extent necessary to quieten one's sexual desire, not for sexual gratification. Otherwise, it would
                           remain sinful. These conditions are extremely rare. 
                           
[derived from: Ibn Abidin's Hashiya, al-Lakhnawi's Naf` al-Mufti wa'l
                           Sa'il, and al-Nahlawi's Durar al-Mubaha, Kamal ibn al-Humam's Fath al-Qadir] 
                           
As for the fast: masturbation that leads to ejaculation invalidates
                           the fast. 
                           
And Allah knows best.