Mishkat al-Masabih 1015
وَعَن عَطاء بن يسَار وَعَنْ أَبِي سَعِيدٍ قَالَ: قَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: «إِذَا شَكَّ أَحَدُكُمْ فِي صَلَاتِهِ فَلَمْ يَدْرِ كَمْ صَلَّى ثَلَاثًا أم أَرْبعا فليطرح الشَّك وليبن عَلَى مَا اسْتَيْقَنَ ثُمَّ يَسْجُدْ سَجْدَتَيْنِ قَبْلَ أَنْ يُسَلِّمَ فَإِنْ كَانَ صَلَّى خَمْسًا شَفَعْنَ لَهُ صَلَاتَهُ وَإِنْ كَانَ صَلَّى إِتْمَامًا لِأَرْبَعٍ كَانَتَا تَرْغِيمًا لِلشَّيْطَانِ» . رَوَاهُ مُسْلِمٌ وَرَوَاهُ مَالِكٌ عَنْ عَطَاءٍ مُرْسَلًا. وَفِي رِوَايَتِهِ: «شَفَعَهَا بِهَاتَيْنِ السَّجْدَتَيْنِ»
From ʿAtaʾ ibn Yasar, and from Abu Saʿid, who said: The Messenger of Allah ﷺ said: "When one of you is in doubt in his prayer and does not know how much he has prayed, three or four, let him cast aside the doubt and build on what he is certain of, then prostrate twice before giving the salam. If he has prayed five, they will make his prayer even for him; and if he prayed to complete four, they will be a humiliation for Shaytan." Reported by Muslim. Malik reported it from ʿAtaʾ in mursal form, and in his narration: "He makes it even with these two prostrations."