Answer
Masturbation is prohibited in Shari?ah.
However, if one ejaculates (sperms comes out) whilst doing so, Ghusl (complete bath) becomes compulsory. After intercourse one should first ensure that all the sperm has come out, by urinating, thereafter should make ghusl, taking care to first remove all impurities from body.
And Allah Ta’ala Knows Best
Mufti Ebrahim Desai