Sayyiduna Abu Sa'id Khudri (may Allah be pleased with him) narrates this statement of the Noble Prophet (peace and blessings be upon him): "When a person, while performing prayer, becomes doubtful whether he has performed three rak'ahs or four, he should perform one more rak'ah, so that his doubt is about having prayed more, then before saying the salam, he should perform the prostration of forgetfulness (sajdah sahw). If he has performed five rak'ahs, then these two (prostrations) will make his prayer even, and if he has performed the complete prayer, then both (prostrations) will be a means of humiliating the devil." In this narration, the narrator has additionally transmitted the words 'before the salam', and Sulayman bin Bilal corroborated him, according to the narration of Musa bin Dawud.
Hadith Referenceسنن الدارقطني / كتاب الصلاة / 1397
Hadith Takhrij«أخرجه مسلم فى ((صحيحه)) برقم: 571، ومالك فى ((الموطأ)) برقم: 315 ، وابن خزيمة فى ((صحيحه)) برقم: 29، وابن حبان فى ((صحيحه)) برقم: 2663، والحاكم فى ((مستدركه)) برقم: 463، والنسائي فى ((المجتبیٰ)) برقم: 1237 ، وأبو داود فى ((سننه)) برقم: 1024، 1026، والترمذي فى ((جامعه)) برقم: 396، والدارمي فى ((مسنده)) برقم: 1536، وابن ماجه فى ((سننه)) برقم: 514، 1204، والدارقطني فى ((سننه)) برقم: 1396، 1397، 1398، 1399، 1400، 1405، 1406، وأحمد فى ((مسنده)) برقم: 11241»