The second most serious thing that breaks the fast or invalidates the fast it is masturbation. And this we get from the Hadith of our beloved Prophet Muhammad (saws),

its mentioned in Sahih Bukhari Vol. No. 3 in the Book of Fasting, Hadith no. 1894 where the Prophet said that

“Allah (swt) said: that all the deeds of the son of Adam are for himself except for fasting, its Saum and I will reward him” and further he says that “the person he leaves, he abstains from eating and drinking and his desires for my sake, Allah says the person abstains from eating, drinking and his desires is for my sake”

Now this desire from here we come to know it includes even masturbation. So when a person masturbates or ejaculates whether by touching his wife or looking at his wife or for other reason or looking at any another woman and if an ejaculation takes place then the fasts gets invalidated. He has to repent to Allah (swt) and complete that day of fasting and he should compensate for this fast, keep this fast later after the Ramadhaan gets over. But here there is no Kaffaara, there’s no penalty because that penalty is only for sexual intercourse. Here because the intercourse hasn’t taken place, there is no penalty, he should only repent, make up that fast, that fast he should complete and then make up for that fast later on.

But if a person does not ejaculate and if there is Madi which comes out, fluid then the fast does not break. Similarly this is the prostatic fluid, the Madhi. And if the Madhi comes out i.e. after urination a white fluid, then too the fast does not break only thing he has to do is after Istinja he should wash the private parts and do Wudhu, the fast does not break. He can complete the fast and continue the fast.

(Source - Dr Zakir Naik)