Abu Ubaidah bin Abdullah narrates from his father (Sayyiduna Abdullah bin Mas'ud, may Allah be pleased with him) that the Prophet Muhammad (peace and blessings be upon him) said: "When you are in prayer and you are in doubt whether you have prayed three or four rak'ahs, and your predominant thought is that you have prayed four, then after reciting the tashahhud, perform two prostrations of forgetfulness (sajda sahw). Do this while you are sitting and before you say the salam. Then after that, recite the tashahhud again and then say the salam." Imam Abu Dawud said: Abd al-Wahid bin Ziyad narrated it from Khusayf, but he did not narrate it as a marfu' (directly attributed to the Prophet) hadith. Sufyan, Sharik and Israil agreed with Abd al-Wahid (in not narrating it as marfu'), but they differed in its wording.
Hadith Referenceسنن الدارقطني / كتاب الصلاة / 1417
Hadith Takhrij«أخرجه النسائی فى ((الكبریٰ)) برقم: 608، وأبو داود فى ((سننه)) برقم: 1028، والبيهقي فى((سننه الكبير)) برقم: 3891، 3925، 3972، والدارقطني فى ((سننه)) برقم: 1417، وأحمد فى ((مسنده)) برقم: 4156» «قال الدارقطني: قال أبو داود ورواه عبد الواحد بن زياد عن خصيف ولم يرفعه ووافق عبد الواحد سفيان وشريك وإسرائيل واختلفوا في متنه ، سنن الدارقطني: (2 / 214) برقم: (1417)»