Hafsah (radiyallāhu ‘anhā, died 45H), the mother of the believers narrated that Allah’s Messenger (ﷺ) said: “Whoever does not commit himself to fasting before dawn (fajr), there is no fast for him.”  and in a narration, “There is no fast for the one who did not make the intention to fast from the night.” 
These and other similar narrations refer to the obligatory fasts. The niyyah (intention to fast) must be present before Fajr. So if a person intended to fast before Fajr began, and then he fell asleep and did not awake until daytime, then his fast is correct because his niyyah (intention) was present — and he did not eat or drink or nullify his fast (in another way). However, if he slept before fajr (i.e. in the night), without an intention to fast, and he did not eat or drink after Fajr (dawn), and then he says, “I will complete my fast and I will not eat or drink.” Then his fast is not correct because he passed a portion of the day without having an intention to fast – and a niyyah cannot be made in retrospect. His fast is not correct. He must withhold from food and drink for the rest of that day and he must make up that day (qadā) after Ramadan. As for the optional (nafl) fast, then it is allowed to make the niyyah for it even after Fajr, in the daytime. So if one wakes up and he did not eat or drink after Fajr and then he intends to fast (as a nafl), then his fast is correct. This is due to the hadeeth of A’ishah (radiyallahu ‘anhā) wherein she said, “Allah’s Messenger entered upon me one day and said, ‘Do you have something [for me to eat]?’ We said, ‘No.’ He then said, ‘In that case, I am fasting [today].’ Then on another day, he came to us and we said, ‘We have been given a gift of hays (a mixture of dates and ghee).’ He said, ‘Show it to me for I had begun the day fasting.’ And then he ate.”  This hadeeth also proves that to break an optional (nafl) fast is allowed and one is not obligated to complete it. The obligatory fast, however, cannot be broken, and to break it is a major sin.
The niyyah should be made daily (i.e. before fajr), and the intention should not be uttered on the tongue by saying, “I intend to fast this day of Ramadān…” Rather, the niyyah is the intent to wake up for suhoor, and the intent to withhold from food and drink — this is a valid niyyah.  The place of the niyyah is in the heart. Vocalising the niyyah and uttering it is an innovation and not from the Sunnah.
 Abu Dawood no. 2454 (authenticated by Al-Albāni), Ibn Mājah no. 1700, Tirmidhi no. 730.
 Dāruqutni 2/172. Authenticated by Al-Albāni in Al-Irwā no. 914.
 Muslim, 1154.
 Shaykh Al-Fawzān in Tas-heel Al-Ilmām, 3/209,210.
 Shaykh Muqbil Ibn Hādi (rahimahullāh) in Fadā’ih wa Nasā’ih, p. 73-74.