I heard the Messenger of Allah ﷺ say, "When one of you is uncertain whether he has prayed one rakah or two, let him count it as one. When he is uncertain whether he has prayed two or three, let him count it as two. When he is uncertain whether he has prayed three or four, let him count it as three. Then let him complete what remains of his prayer, so that any doubt falls on the side of having prayed extra. Then let him perform two prostrations while seated, before giving the salam."
حدثنا أبو يوسف الرقي محمد بن أحمد الصيدلاني حدثنا محمد بن سلمة عن محمد بن إسحق عن مكحول عن كريب عن ابن عباس
سمعت رسول الله ﷺ يقول إذا شك أحدكم في الثنتين والواحدة فليجعلها واحدة وإذا شك في الثنتين والثلاث فليجعلها ثنتين وإذا شك في الثلاث والأربع فليجعلها ثلاثا ثم ليتم ما بقي من صلاته حتى يكون الوهم في الزيادة ثم يسجد سجدتين وهو جالس قبل أن يسلم
[Hasan] Tirmidhi transmitted it in Salah, in the chapter on one who doubts whether he has added or omitted, hadith no. 398, from the hadith of Ibn Ishaq with this wording, and he said, "It is hasan, sahih, and rare." Hakim graded it sahih (1/324-325), as did Dhahabi. Ibn Ishaq stated explicitly that he heard it directly, as recorded by Abu Yaala, hadith no. 839.