All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
The prayer that is now called Taraweeh prayer was derived from the night prayer which the Prophet prayed with his companions during the month of Ramadan. The Prophet said: “The prayer of the night is in twos and twos, and if one fears that Fajr (dawn) would break before having performed his Witr prayer, then he should finish his night prayers by performing one Witr Rak'ah.” [Al-Bukhari and Muslim]
It is known that the Prophet did not pray the night prayer regularly with his companions during Ramadan because he did not want the night prayer in congregation to become an obligation upon his Ummah.
There is no Hadeeth indicating the number of Rak’ahs the Prophet prayed with his companions. It is known that he prayed eight Rak'ahs as voluntary prayers in his home.
Muslims in the Middle East pray as they like; some pray eight Rak'ahs and others pray twenty Rak'ahs as is done in the two holy mosques in Makkah and Madeenah.
The current practice of praying the night prayer in congregation during Ramadan was initiated during the Caliphate of ‘Umar . What ‘Umar, may Allaah pleased with him, did by gathering Muslims to pray with Ubay ibn Ka’b, is true and sound and it is according to the Sunnah of the Prophet . But we do not know how many Rak'ahs Ubay prayed, whether it was twenty Rak'ahs or not.
Is the narration concerning twenty Rak'ahs correct or not? This is a controversial issue among Muslim scholars. If we suppose that ‘Umar, may Allaah pleased with him, actually told Ubay to pray twenty Rak'ahs, this could be Ijtihad (a juristic opinion) from him and the companions who were with him. There is no contradiction between the Sunnah and what they did as clarified earlier. We are, however, ordered to follow the rightly guided Caliphs and the consensus of the companions if we know for a fact that the consensus of these companions did actually happen over a given issue.
For more benefit on Taraweeh prayer, please refer to Fatwa 82508, 85638, 88951 and 318571.
Allah knows best.