Zoheir Ali Esmail, Shaykh Zoheir Ali Esmail has a Bsc in Accounting and Finance from the LSE in London, and an MA in Islamic Studies from Middlesex University. He studied Arabic at Damascus University and holds a PhD... Answer updated 4 years ago

Thank you for your question. The following is the ruling found in Ay Sistani’s Islamic Laws translated by Shaykh Muhammad Ali Ismail (1) 303-304. Your question pertains to the first scenario for someone whow doubts about the number of rakats in a four rakat prayer:

Ruling 1185. In nine situations if one doubts about the number of rakʿahs in a four rakʿah prayer, he must think [about the doubt]; then, if he becomes certain or he supposes that a particular possibility is correct, he must act according to that possibility and complete the prayer; otherwise, he must act according to the instructions that will be mentioned later. The nine situations are as set out below. 

First: after starting the second sajdah, one doubts whether he has performed two rakʿahs or three rakʿahs. In this situation, he must assume he has performed three rakʿahs and perform one more rakʿah and complete the prayer, and after the prayer he must perform one rakʿah of ṣalāt al-iḥtiyāṭ in a standing position; and based on obligatory precaution, performing two rakʿahs in a sitting position will not suffice. 

View 2 other responses to this question