If someone invalidates some of his fasts due to masturbation, but wasn’t aware that such act breaks the fast, and he also doesn’t remember the number of days he missed, what shall he do? May Allah bless you.
He needs to make isthigfaar, ask Allah for forgiveness and repent with the intention of not repeating this sin again. He needs to compensate for the days he missed. Let him try to make an estimate of the days he missed, to compensate them. And it would better for him to make naafilah sawm after compensating and this naafilah will compensate for anything more that is missing. He can fast every Mondays and Thursdays if it is needed to compensate for the missed fasts. This would be better.