According to a fitwa from Shiite Holly Najaf in Iraq if you masturbate in Ramadan without discharging your sperm that will be ok but if you discharge your sperm it will become a sin and your fast becomes invalid. To remove the sin, you have to feed 60 poor persons. You have to give each one a loaf of bread or 750g wheat.