Short answer
Yes. Your fast is valid even if you sleep for most or all of the day, as long as you made the intention to fast. But sleeping through Dhuhr and Asr without praying is a sin, and sleeping away the days of Ramadan loses much of its reward.
The fast is valid while asleep, even for the whole day, provided the intention was made. Sleep is permissible, and a midday nap (qaylulah) is sunnah. Missing a fard prayer through careless oversleeping is sinful, and missed prayers must be made up.
The four schools agree on this.
Explanation
Fasting means holding back from what breaks the fast, with intention. A sleeping person is holding back, so the fast counts. The four schools agree that sleep during the fasting day does not harm the fast. Being unconscious for the whole day is a separate question that the schools treat differently.
The prayers come first. The real problem with sleeping all day is the prayers, not the fast. Setting no alarm and sleeping through Dhuhr and Asr is a sin. Missing a prayer does not break the fast, but you must pray it as soon as you wake. See fasting without praying.
About the famous saying. The words "the sleep of the fasting person is worship" are often quoted as a hadith, but the hadith scholars graded them weak. Sleep taken with a good intention, to have strength for taraweeh and suhoor, can still be rewarded. It is not a reason to sleep the whole day.
A balanced day:
- Sleep after Fajr or take a midday nap if you were up for taraweeh and suhoor.
- Set alarms for Dhuhr and Asr.
- Keep some of the day for Quran, dhikr and dua, especially before iftar.
- Follow the advice the Prophet ﷺ gave a Companion who overdid his worship: fast and break your fast, pray at night and sleep, for your body has a right over you.
The evidence
Quran, Surah Al-Baqara 2:187
أُحِلَّ لَكُمْ لَيْلَةَ ٱلصِّيَامِ ٱلرَّفَثُ إِلَىٰ نِسَآئِكُمْ ۚ هُنَّ لِبَاسٌۭ لَّكُمْ وَأَنتُمْ لِبَاسٌۭ لَّهُنَّ ۗ عَلِمَ ٱللَّهُ أَنَّكُمْ كُنتُمْ تَخْتَانُونَ أَنفُسَكُمْ فَتَابَ عَلَيْكُمْ وَعَفَا عَنكُمْ ۖ فَٱلْـَٰٔنَ بَٰشِرُوهُنَّ وَٱبْتَغُوا۟ مَا كَتَبَ ٱللَّهُ لَكُمْ ۚ وَكُلُوا۟ وَٱشْرَبُوا۟ حَتَّىٰ يَتَبَيَّنَ لَكُمُ ٱلْخَيْطُ ٱلْأَبْيَضُ مِنَ ٱلْخَيْطِ ٱلْأَسْوَدِ مِنَ ٱلْفَجْرِ ۖ ثُمَّ أَتِمُّوا۟ ٱلصِّيَامَ إِلَى ٱلَّيْلِ ۚ وَلَا تُبَٰشِرُوهُنَّ وَأَنتُمْ عَٰكِفُونَ فِى ٱلْمَسَٰجِدِ ۗ تِلْكَ حُدُودُ ٱللَّهِ فَلَا تَقْرَبُوهَا ۗ كَذَٰلِكَ يُبَيِّنُ ٱللَّهُ ءَايَٰتِهِۦ لِلنَّاسِ لَعَلَّهُمْ يَتَّقُونَ ﴿١٨٧﴾
It has been made permissible for you the night preceding fasting to go to your wives [for sexual relations]. They are clothing for you and you are clothing for them. Allah knows that you used to deceive yourselves, so He accepted your repentance and forgave you. So now, have relations with them and seek that which Allah has decreed for you. And eat and drink until the white thread of dawn becomes distinct to you from the black thread [of night]. Then complete the fast until the sunset. And do not have relations with them as long as you are staying for worship in the mosques. These are the limits [set by] Allah, so do not approach them. Thus does Allah make clear His ordinances to the people that they may become righteous.
The fast is completed by holding back until sunset, awake or asleep.
Sahih al-Bukhari 1975
Sahih... صم وأفطر وقم ونم فإن لجسدك عليك حقا ...
"Fast and break your fast, pray at night and sleep, for your body has a right over you."
Sleep is part of a balanced life of worship.
Where the ruling is recorded
- Radd al-Muhtar (Ibn Abidin), Kitab al-Sawm, chapter on what breaks the fast and what does not. Sleep during the fasting day does not affect the fast.
- al-Majmu' (Nawawi), Kitab al-Siyam. Sleeping through the whole day does not harm the fast, unlike being unconscious for the whole day.
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.