Abu Sa'id al-Khudri, may Allah be pleased with him, reported that the Prophet ﷺ said: "If one of you doubts in his prayer and does not know how many he has prayed, three or four, let him throw away the doubt and build on what he is sure of, then make two prostrations before the salam." The Prophet ﷺ added that if he had prayed five, the two prostrations make his prayer even, and if it was four, they are a humiliation for Shaytan (Sahih Muslim 571).
Ibn Mas'ud reported another wording: "If one of you doubts in his prayer, let him aim for what is correct, complete his prayer on that basis, then give the salam and make two prostrations" (Sahih al-Bukhari 401; Sahih Muslim 572). Scholars reconcile the two reports in different ways. The Shafi'i and Maliki schools read both as building on what is certain, which is the smaller number. The Hanafi school, and one narration in the Hanbali school, build on strong probability when there is one, and on the smaller number when there is not. A passing whisper of doubt with no real basis should be ignored.