The World Federation One Stop Fiqh

Ruling 1209

If a person doubts whether he has performed three or four rakʿahs, and while performing one rakʿah of ṣalāt al-iḥtiyāṭ in a standing position he remembers that he had performed three rakʿahs, he must abandon his ṣalāt al‐iḥtiyāṭ; and in the event that he remembers this before going into rukūʿ, he must perform one rakʿah in a way that it connects with his prayer, and his prayer will be valid. And for performing an additional salām, based on obligatory precaution, he must perform sajdatā al‐sahw. However, if he remembers [that he had performed three rakʿahs] after going into rukū, he must perform the prayer again; and based on obligatory precaution, he cannot suffice with joining the remaining rakʿah to his prayer.