عَنْ أَبِي عُبَيْدَةَ عَنْ أَبِيهِ عَبْدِ اللَّهِ بْنِ مَسْعُودٍ عَنِ النَّبِيِّ صَلَّى اللَّهُ عَلَيْهِ وَآلِهِ وَسَلَّمَ قَالَ: ((إِذَا كُنْتَ فِي الصَّلَاةِ فَشَكَكْتَ فِي ثَلَاثٍ أَوْ أَرْبَعٍ، وَأَكْثَرُ ظَنِّكَ عَلَى أَرْبَعٍ، تَشَهَّدْتَّ ثُمَّ سَجَدْتَّ سَجْدَتَيْنِ وَأَنْتَ جَالِسٌ قَبْلَ أَنْ تُسَلِّمَ، ثُمَّ تَشَهَّدْتَّ أَيْضًا ثُمَّ سَلَّمْتَ))
It is narrated from Sayyiduna Abdullah bin Mas'ud (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: When you are in prayer and you doubt whether you have prayed three or four rak'ahs, but your predominant thought is that it is four, then recite the tashahhud and, before the salam, perform two prostrations while sitting, then recite the tashahhud again and after that, say the salam.