Short answer
Taraweeh is prayed after Isha and its time lasts until true dawn. In the Hanafi school it is best in the first third or half of the night, and the sounder view is that praying it after midnight is not disliked. Prayed before Isha, it does not count as taraweeh.
The time of taraweeh is after the Isha prayer until true dawn, and it may be prayed before or after witr. Delaying it to a third or half of the night is mustahabb, and the sounder view is that praying it after half the night is not makruh. A missed taraweeh is not made up.
The four schools agree on this.
Explanation
Taraweeh is the night prayer of Ramadan. Its time follows Isha: once you have prayed Isha, you may pray taraweeh any time until Fajr begins. Most masjids pray it straight after Isha in congregation, which is easiest for people and the established practice.
After midnight. Some people work late or miss the masjid and wonder if 12 or 1 am is too late. It is not. The Hanafi texts discuss praying it after half the night, and the sounder position is that it is not disliked, since it is a night prayer and the later part of the night has its own virtue. Just finish before true dawn.
Taraweeh and witr. The sunnah is to make witr the last prayer of the night. In Ramadan, Hanafi masjids pray witr in congregation after taraweeh. If you pray witr with the imam and then pray more taraweeh at home, it is still valid. If you plan to wake for tahajjud, you may delay witr to the end of the night. See how to pray witr.
Before Isha. Taraweeh prayed before Isha is not taraweeh, only a voluntary prayer. Pray Isha first.
If you missed it. Taraweeh has no make-up in the Hanafi school. Pray it the next night. For the number of rakat, see how many rakat is taraweeh, and for praying it at home, see taraweeh at home.
The evidence
Quran, Surah Al-Muzzammil 73:20
۞ إِنَّ رَبَّكَ يَعْلَمُ أَنَّكَ تَقُومُ أَدْنَىٰ مِن ثُلُثَىِ ٱلَّيْلِ وَنِصْفَهُۥ وَثُلُثَهُۥ وَطَآئِفَةٌۭ مِّنَ ٱلَّذِينَ مَعَكَ ۚ وَٱللَّهُ يُقَدِّرُ ٱلَّيْلَ وَٱلنَّهَارَ ۚ عَلِمَ أَن لَّن تُحْصُوهُ فَتَابَ عَلَيْكُمْ ۖ فَٱقْرَءُوا۟ مَا تَيَسَّرَ مِنَ ٱلْقُرْءَانِ ۚ عَلِمَ أَن سَيَكُونُ مِنكُم مَّرْضَىٰ ۙ وَءَاخَرُونَ يَضْرِبُونَ فِى ٱلْأَرْضِ يَبْتَغُونَ مِن فَضْلِ ٱللَّهِ ۙ وَءَاخَرُونَ يُقَٰتِلُونَ فِى سَبِيلِ ٱللَّهِ ۖ فَٱقْرَءُوا۟ مَا تَيَسَّرَ مِنْهُ ۚ وَأَقِيمُوا۟ ٱلصَّلَوٰةَ وَءَاتُوا۟ ٱلزَّكَوٰةَ وَأَقْرِضُوا۟ ٱللَّهَ قَرْضًا حَسَنًۭا ۚ وَمَا تُقَدِّمُوا۟ لِأَنفُسِكُم مِّنْ خَيْرٍۢ تَجِدُوهُ عِندَ ٱللَّهِ هُوَ خَيْرًۭا وَأَعْظَمَ أَجْرًۭا ۚ وَٱسْتَغْفِرُوا۟ ٱللَّهَ ۖ إِنَّ ٱللَّهَ غَفُورٌۭ رَّحِيمٌۢ ﴿٢٠﴾
Indeed, your Lord knows, [O Muhammad], that you stand [in prayer] almost two thirds of the night or half of it or a third of it, and [so do] a group of those with you. And Allah determines [the extent of] the night and the day. He has known that you [Muslims] will not be able to do it and has turned to you in forgiveness, so recite what is easy [for you] of the Qur'an. He has known that there will be among you those who are ill and others traveling throughout the land seeking [something] of the bounty of Allah and others fighting for the cause of Allah. So recite what is easy from it and establish prayer and give zakah and loan Allah a goodly loan. And whatever good you put forward for yourselves - you will find it with Allah. It is better and greater in reward. And seek forgiveness of Allah. Indeed, Allah is Forgiving and Merciful.
Night prayer may be spread across the night as people are able.
Sahih al-Bukhari 37
Sahih... من قام رمضان إيمانا واحتسابا غفر له ما تقدم من ذنبه ...
"Whoever stands in prayer in Ramadan out of faith and hoping for reward will have his past sins forgiven."
The night prayer of Ramadan is a great sunnah, whatever part of the night it is prayed in.
Sahih al-Bukhari 998
Sahih... اجعلوا آخر صلاتكم بالليل وترا ...
"Make witr the last of your prayers at night."
Witr is best at the end of the night prayer.
Where the ruling is recorded
- Radd al-Muhtar (Ibn Abidin), Kitab al-Salah, chapter on witr and voluntary prayers, section on taraweeh. Its time is after Isha until dawn; delaying it past half the night is not disliked in the sounder view.
- Nur al-Idah with Maraqi al-Falah, Kitab al-Salah, chapter on taraweeh. Taraweeh is an emphasised sunnah prayed after Isha, before or after witr.
Checked by our team. For a more accurate answer to your own situation, consult a scholar. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.