Sayyiduna Abdullah bin Mas'ud (may Allah be pleased with him) says: The Prophet (peace and blessings be upon him) said seven takbirs, and five, and four. When you put the imam forward, say as many takbirs as the imam says.
Al-Tabarani recorded it in al-Mu'jam al-Awsat. Its chain contains Ata' bin al-Sa'ib, who has been criticised, and he is hasan al-hadith (sound in hadith).
Hadith Referenceمجمع الزوائد ومنبع الفوائد / كتاب الجنائز / 4176