Sayyiduna Abdullah bin Umar (may Allah be pleased with them both) said that the Messenger of Allah (peace and blessings be upon him) said: "When one of you is praying and does not remember how many rak'ahs he has prayed, three or four, let him pray one rak'ah, performing its bowing and prostrations well, and then (at the end) perform two prostrations."
Its narrators are thiqat (trustworthy), and Malik bin Anas reported it as mawquf (a saying of the Companion) in al-Muwatta.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 3809