This question already has an answer here:
I am a 17-year old boy, and I want to know if Islam allows one to rub one's penis to get out sperms (semen).
When I get into for bath that time I feel something different, or sexual desire, and I won't be able to stop my hand from rubbing my penis, and as a result sperm comes out, and I feel something different, but after rubbing penis I wash it from water as I am bathing. So, I wanted to know that it is good habit or bad habit related to Islam?
If it is bad habit I ask for forgiveness for Allah for that all thing! If it is not bad then it's ok.