It is narrated from a man, from the Prophet (peace and blessings be upon him), that he (peace and blessings be upon him) said: "When you come and the imam is bowing, then join in; and if he is in prostration, then (join) too; but if you did not bow with him, do not count the prostration."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 2576