Basically, after you masturbate, pray 2 rakats. The more rakats the better. So, here is how it works. Shaytaan is the one whispering in your ear, telling you to masturbate. But, when you pray 2 rakats after masturbating, Shaytaan will be like "Oh no! After Ali Masturbates, he prays 2 rakats! That means that I have to stop him from masturbating, because the last thing I want him to do is pray!" Therefore, he will tell you "Ali, Don't masturbate!", when you are getting urges.