Praise be to Allah.
Is masturbation haram?
No doubt masturbation is haram according to most of the scholars, as Shaykh al-Islam Ibn Taymiyah (may Allaah have mercy on him) said. If this happens in Ramadan, this is worse, and if there is ejaculation of sperm because of the masturbation , the violation of the sanctity of the fast is even more severe in sin.
Does masturbation break your fast?
From the time the maniy (semen) is ejaculated, the fast is broken, but the person should still fast for the rest of that day. It is not permissible for him to stop fasting, because of the sanctity of the month.
You have to repent for breaking your fast by deliberately ejaculating, and you also have to repent for not keeping the fast for the rest of the day and for violating the sanctity of the fast by doing something else that broke the fast, namely eating food.
You also have to fast one day to make up for breaking your fast. Increase the number of good deeds (hasanat) you do and observe nafl (supererogatory) fasts, for good deeds (hasanat) cancel out bad deeds (sayyiat). And Allaah is Forgiving and Merciful.
And Allah knows best.