Masturbation is one of the things that invalidate the fast, and the one who does that has to make up the day that he broke his fast. He must also repent from this great sin.
Shaykh Ibn Baaz said:
Masturbation during the day in Ramadaan invalidates the fast if it is done deliberately and semen is emitted as a result. The person must make up the day if that was an obligatory fast, and he must repent to Allaah, because masturbation is not permissible whether one is fasting or not. It is the action which people call the “secret habit”.
Fataawa al-Shaykh Ibn Baaz, 15/267
Shaykh Ibn ‘Uthaymeen (may Allaah have mercy on him) said:
If a fasting person masturbates and ejaculates, this breaks his fast, and he has to make up the fast of the day on which he masturbated, but he does not have to offer any expiation, because the expiation is only required of one who has intercourse. And he has to repent from what he did.
Fataawa Arkaan al-Islam, p. 478
This applies if he masturbated and ejaculated; if he did not ejaculate then this does not break the fast.
Shaykh Ibn ‘Uthaymeen (may Allaah have mercy on him) said in al-Sharh al-Mumti’ (6/388):
If he masturbated without ejaculating, this does not invalidate the fast.
And Allaah knows best.