Short answer
In the Hanafi school there are three times when no prayer is valid: while the sun is rising, when it is at its zenith (zawal) and while it is setting, except that day's Asr. There are two more times, after the Fajr fard and after the Asr fard, when nafl is makruh but qada is allowed.
At sunrise, zawal and sunset no prayer is valid: fard, qada, nafl, janazah prepared earlier, or sajdah tilawah of an earlier verse, except the same day's Asr, which is valid but makruh. After the Fajr fard until sunrise and after the Asr fard until sunset, nafl and sunnah are makruh tahrimi, while qada, janazah and sajdah tilawah are allowed.
Other madhhabs
- Shafi'i
- Prayers that have a reason, such as qada, tahiyyat al-masjid, janazah and the sunnah after wudu, are allowed even in the forbidden times; the zawal on Friday is excepted.
- Maliki
- Missed fard prayers are made up at any time; nafl is forbidden at sunrise and sunset and disliked after Fajr and Asr.
- Hanbali
- Missed fard prayers are made up at any time, and some prayers with a reason, like tahiyyat al-masjid, are allowed.
Explanation
The Companion Uqbah ibn Amir said there were three times when the Prophet ﷺ forbade us to pray or bury our dead: when the sun rises until it is up, when it stands at its height until it passes, and when it begins to set until it has set. Another hadith forbids prayer after Fajr until the sun rises high and after Asr until it sets.
1. Times when no prayer is valid (Hanafi):
- Sunrise: from the start of sunrise until the sun has fully risen, about 15 to 20 minutes.
- Zawal: the short time when the sun is at its highest, just before Dhuhr begins. Many timetables mark a few minutes before Dhuhr to be safe.
- Sunset: from when the sun turns pale yellow until it has set. Only that day's Asr, if you are late, may be finished then, and delaying it so far is makruh.
2. Times when only nafl is disliked:
- After praying the Fajr fard until sunrise. Even before the fard, after true dawn, nothing but the two sunnah of Fajr is prayed.
- After praying the Asr fard until the sun yellows.
In these two times you may pray qada of missed prayers, a janazah, and sajdah tilawah. Some other times are also disliked for nafl, such as during the khutbah and after the iqamah has been called.
Du'a, dhikr and Quran recitation are allowed at all times. For making up prayers, see making up missed prayers; for sunrise in particular, see praying Fajr after sunrise.
The evidence
Sahih Muslim 831
Sahih... ثلاث ساعات كان رسول الله صلى الله عليه وسلم ينهانا أن نصلي فيهن ...
"There were three times in which the Messenger of Allah forbade us to pray."
Sunrise, zenith and sunset are the three forbidden times.
Sahih al-Bukhari 586
Sahih... لا صلاة بعد الصبح حتى ترتفع الشمس ولا صلاة بعد العصر حتى تغيب الشمس ...
"There is no prayer after Fajr until the sun rises high, and no prayer after Asr until the sun sets."
Voluntary prayer is not prayed after the Fajr and Asr prayers.
Where the ruling is recorded
- Nur al-Idah with Maraqi al-Falah, Chapter on the times in which prayer is disliked. Lists the three times when no prayer is valid and the times when only nafl is disliked.
- al-Hidaya, Kitab al-Salah, chapter on times in which prayer is disliked. The exception of the same day's Asr and the permission of qada after Fajr and Asr.
- al-Majmu' (Nawawi), Chapter on the times in which prayer is forbidden. The Shafi'i permission for prayers that have a reason.
This answer is pending review by the scholars on our team. 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.