Tips on how to give up masturbation
1. The motive to seek a cure for this problem should be solely following Allah's orders and fearing His punishment.
2. A permanent and quick cure from this problem lies in marriage as soon as the person is able
3. Keeping oneself busy with what is good for this world and the Hereafter is essential in breaking this habit.
4. Lowering the gaze (from looking at forbidden things such as pictures, movies etc.) will help suppress the desire before it leads one to commit the haram (forbidden).
Allah's Messenger (peace and blessings be upon him) said: "Do not follow a casual (unintentional) look (at forbidden things) with another look."
⏩ This is a general instruction by the Prophet (peace and blessings be upon him) to abstain from all that may sexually excite a person because it might lead him/her to commit the haram (forbidden).
5. Using one's available leisure time in worshipping Allah and increasing religious knowledge.
6. Being cautious not to develop any of the medical symptoms that may result from masturbation such as weak eyesight, weak nervous system, and/or back pain. More importantly, feelings of guilt and anxiety that can be complicated by missing obligatory prayers because of the need to shower (ghusl) after every incidence of masturbation, especially in the winter, and the invalidating of the fast.
7. Avoiding the illusion that some youth have that masturbation is permissible because it prevents them from committing illegal sexual acts such as fornication or even homosexuality, while they may not be at the gates of that immorality to begin with.
8. Strengthening one's willpower and not surrendering to the shaytan, and avoiding spending time alone as recommended by the Prophet (peace and blessings be upon him) when he said "Do not spend the night alone"
9. Following the Prophet's (peace and blessings be upon him) aforementioned hadeeth and fasting when possible, because fasting will temper one's sexual desire and keep it under control.
10. Trying to follow the Prophet's (peace and blessings be upon him) recommendation concerning the etiquette of getting ready for bed, such as reading the well-known supplications, sleeping on the right side, and avoiding sleeping on the belly (the Prophet-peace and blessings be upon him- forbade sleeping on the belly).
11. Striving hard to be patient and chaste, because persistence will eventually, Allah willing, lead to attaining those qualities as second nature, as the Prophet (peace and blessings be upon him) explains in the following hadith:
"Whoever seeks chastity Allah will make him chaste, and whoever seeks help from none but Allah, He will help him, and whoever is patient He will make it easy for him, and no one has ever been given anything better than patience." Al-Bukhari:1469.
12. If one falls into this sin, they must hasten to repent, asking forgiveness from Allah, doing good deeds, and not losing hope and feeling despair; these are all prerequisites to curing this problem. Note that losing hope is one of the major sins punishable by Allah.
13. Finally, Allah is the Most Merciful and He always responds to whoever calls on Him. So, asking for Allah's forgiveness and help will be accepted, by His will.
P.S: medication to diminish one's sexual desire is strictly prohibited because it might permanently affect one's sexual ability.