´It was narrated that ‘Abdur-Rahman bin ‘Awf said:` “I heard the Messenger of Allah (ﷺ) say: ‘If anyone of you is uncertain as to whether he has prayed one or two Rak’ah, let him assume it is one. If he is uncertain as to whether he has prayed two or three, let him assume it is two. If he is uncertain as to whether he has prayed three or four, let him assume it is three. Then let him complete what is left of his prayer, so that the doubt will be about what is more. Then let him prostrate twice while he is sitting, before the Taslim (saying the Salam).’”
Hadith Referenceسنن ابن ماجه / كتاب إقامة الصلاة والسنة / 1209
1؎ : The meaning of this hadith is that when a person’s opinion does not settle on any side, and both sides are equal—that is, there is no predominance of assumption (ghalabat al-zann) towards either side—then he should choose the lesser number, because there is precaution in this. If there is a mistake, it will only be that the prayer becomes more, and that is better than it becoming less. And in this state, this hadith will not be contrary to the following ahadith in which the mention of thinking (reflection) occurs. Some have said that one should think, rather, in every situation one should return to certainty (yaqin), and choose the lesser number. And Abu Hanifah rahimahullah said that if this happens for the first time, he should repeat the prayer from the beginning; if it happens the second or third time, he should reflect and act upon whichever opinion he feels content with; if he does not feel content with any opinion, then he should choose the lesser number.