The Prophet ﷺ said, "If one of you is uncertain about his prayer and does not know whether he has prayed two or three units, let him cast aside the doubt and build upon what he is certain of."
عن النبي ﷺ قال: إذا شك أحدكم في صلاته فلم يدر اثنين صلى، أو ثلاثا، فليلق الشك، وليبن على اليقين.
Bayhaqi narrated it in Al-Kubra (2/333) from Abu Abdullah Hafiz in Al-Fawaid al-Kabir of Abu Abbas, "Abu Abbas Muhammad bin Yaqub told us, Ahmad bin Hazim bin Abu Ghurza told us, Jafar informed us, Saeed bin Abu Aruba informed us, from Qatada, from Anas," and he related it. Its chain is sahih, and Jafar is Ibn Awn, who is trustworthy and among the narrators of the two sahih collections.It has a corroborating narration from the hadith of Abdul-Rahman bin Awf, though there is some discussion about it. Tirmidhi (398) and Ibn Majah (1209) both narrated it through Muhammad bin Salama, from Muhammad bin Ishaq, from Makhul, from Kurayb, from Ibn Abbas, from Abdul-Rahman bin Awf, who said, I heard the Prophet ﷺ say, "If one of you becomes confused in his prayer and does not know whether he prayed one or two, let him settle on one. If he does not know whether he prayed two or three, let him settle on two. If he does not know whether he prayed three or four, let him settle on three, and let him prostrate twice before he gives the salutation."Tirmidhi said, Hasan sahih, and in one copy, hasan gharib sahih. I say, it contains Muhammad bin Ishaq, who practices tadlis and narrated this with an ambiguous form of transmission (anana), except that he explicitly stated direct transmission in the narration of Abu Yaala (839).Hakim (1/324) narrated it through Muhammad bin Salama with the same chain, and mentioned in it the story of Umar bin Khattab with Ibn Abbas, which is Ibn Abbas's statement, I sat with Umar bin Khattab while he was caliph, and he said, "Ibn Abbas, have you heard from the Messenger of Allah ﷺ or from any of his companions anything mentioning what the Messenger of Allah ﷺ commanded when a person becomes confused in his prayer?" I said, "No." Or, "Have you heard, Commander of the Faithful?" He said, "No." Then Abdul-Rahman bin Awf came in to us, and he said, "What are you two discussing?" Umar said, "I asked him whether he had heard the Messenger of Allah ﷺ or any of his companions mention what the Messenger of Allah ﷺ commanded when a person becomes confused in his prayer."Abdul-Rahman said, "I have knowledge of that." Umar said, "Come then, for you are the trusted and accepted one." So Abdul-Rahman said, "I heard the Messenger of Allah ﷺ say, 'If one of you is uncertain between two, let him settle on one. If he is uncertain between two and three, let him settle on two. If he is uncertain between three and four, let him settle on three, then complete what remains of his prayer so that the uncertainty falls on the side of excess, then let him prostrate twice while sitting, before giving the salutation.'"Hakim said, Sahih according to the standard of Muslim, corroborating the hadith of Abdul-Rahman bin Thabit bin Thawban. I say, the hadith of Abdul-Rahman bin Thabit was narrated by Hakim through Ammar bin Mutar Rahawi, from him, from his father, from Makhul, from Kurayb the freedman of Ibn Abbas, from Ibn Abbas, from Abdul-Rahman bin Awf, who said, the Messenger of Allah ﷺ said, "Whoever becomes confused in his prayer between three and four, let him complete it, for excess is better than deficiency." Hakim said, sahih chain, but Dhahabi challenged this, saying, "They abandoned Ammar."I say, along with the tadlis of Ibn Ishaq, there is also disagreement over his transmission. Ahmad (1677) narrated it from Ismail bin Ulaya, from Ibn Ishaq, from Makhul, in mursal form. Muhammad bin Ishaq said, "Husayn bin Abdullah said to me, 'Did he give you it with a full chain?' I said, 'No.' He said, 'But he told me that Kurayb, the freedman of Ibn Abbas, told him, from Ibn Abbas, who said, I sat with Umar bin Khattab,'" and he then related the story as it went before. Husayn is very daif. This is likewise how Bayhaqi (2/332) reported it, and he said, "So the connection of the hadith goes back to Husayn bin Abdullah, who is daif, except that it has a corroborating witness from the hadith of Makhul." By this he means the hadith of Abdul-Rahman bin Thabit, from his father, from Makhul, as mentioned before, and Makhul likewise practices tadlis and narrated this with an ambiguous form of transmission.The hadith has other connected paths, but they are all daif. Ibn Hajar mentioned them in Al-Talkhis (2/5) and said, "It is a defective hadith (mu'allal)." So it remains uncertain between being disconnected and being connected but daif, along with tadlis.