Fasting Ramadan is obligatory:
1- When Sha'ban (The month that precedes Ramadan in the lunar calendar) has completed thirty days.
2- When a person, even if he is corrupt, sees the new moon (crescent) of Ramadan.
Ibn Umar (G. p. H) narrated that he heard the Messenger of Allah (P. B. U. H) saying: "Fast upon sighting it (i. e. The new moon of Ramadan)(the crescent) and break fast upon sighting it (The new moon of 'Shawwal (the succeeding lunar month) but if it is too overcast to be seen then act on estimation".
[Al-Bukhari, Vol. 2, The Book of Fasting, Chapter 5/1801].
And in a narration by Abu Hurayrah (G. p. H)
"... Then complete Sha'ban to thirty days".
[Al-Bukhari, Vol. 2, The Book of Fasting, Chapter 11/1810].
3- When someone is informed of sighting the crescent by a trustworthy person or by someone who does not tell lies, even if the ruler has not accepted his/ her testimony (because of not having all the qualifications of an acceptable witness). (pa:290 )
If one fasts and it turns out that it was Ramadan indeed, then one's fasting is valid.
4- When the sighting is established by the testimony of a just witness to the ruler.
Sighting the new moon of Ramadan is established to the ruler by the testimony of a single witness provided he is just, male, and accountable (for the duties of Islam).
Abdullah ibn Umar (G. p. H) narrated: "People competed to sight the crescent and I told the Messenger of Allah (P. B. U. H) that I sighted it so he fasted and ordered the people to fast".
[Abu-Dawood, Vol. 2, The Book of Fasting, Chapter 14/2342].
Furthermore, because sighting obligates fasting it should be accepted from a single witness as a precaution to fulfill the obligation of Ramadan.
Sighting the new moon in months other than Ramadan is established by the testimony of two just witnesses.
Thus, sighting the moon of Shawwal (the iftar crescent) is established only when two witnesses are available.
That is because this sighting will end fasting therefore the number of witnesses is a precaution to fulfill the obligation of Ramadan.
If someone sees the crescent of Shawwal alone, he should break fast but in secret so as not to be accused in his religion.
If the crescent is sighted in one place, then all places which lie on the same longitude (Actually, the word in Arabic is "matali"' which is plural for 'the place the moon (in this case), rises from) should fast.
The evidence that it is not obligatory to fast if the places are on different longitudes is what Kuraib narrated: "That Umm Al-FadI bint Al-Hareth sent him to Mu'awiya in Sham (Another name for southern Syria, especially Damascus).
He said: 'I came to Sham and saw to her need, then Ramadan commenced while I was in Sham.
I saw the crescent on Friday eve (The night before the day of Friday) then I returned to Medina at the end of the month so Abdullah ibn Abbas (G. p. H) asked me (about my trip) then mentioned the crescent and said: 'When did you sigh t the crescent?'
I said: 'We sighted it on Friday night. '
He said: 'You saw it ?'
I said: 'Yes, and the people saw it and fasted, and so did Mua'wiya.
He said: 'But we saw it on Saturday night so we will keep fasting until we complete thirty days or see the crescent. '
I said: 'Shouldn't we suffice ourselves with Mua'wiya's sighting and his
fasting ?'
He said: 'No, that's what the Messenger of Allah (P. B. U. H) ordered us to do".
[Muslim, Vol. 2, The Book of Fasting, Chapter 5/28].
If people are in doubt as to whether they are on the same longitude (have the same matlli') or not then those who have not sighted the crescent do not need to fast because fasting is only obligated by sighting for the (above mentioned) hadith and sighting was not proven to them because it was not proven that they are close to the place of sighting.
If the crescent is seen in the daytime then it is the new moon of the coming night whether it was seen before the meridian or after.
Abu Wa'il (G. p. H) said:
"A letter from Umar (G. p. H) reached us while we were in Khanqeen (A town in Iraq near to Baghdad) that some crescents are larger than others so if you see the crescent in the daytime then do not break fast until sunset unless two Muslim men testify that they had sighted the crescent the previous night".
[Al-Bayhaqi, Vol. 4, page 213]. (pa:291 )
If one travels to another country- be it at the beginning or end of the month- one should fast or not according to what the people of that country are doing.
An imprisoned person should, to the best of his ability, figure out when Ramadan starts and fast accordingly.
If he remains in doubt and never finds out whether his fasting coincided with Ramadan or not then his fast is valid.
If his fasting turns out to have been in Ramadan, or after it, his fast is still valid.
However, if it turns out to have been before Ramadan, then there are two possibilities:
-a- If he finds out before Ramadan has started he should definitely fast Ramadan because he is able to fast it on time.
-b- If he finds out after Ramadan is over he should make up for his fast.
If he fasts without trying to figure out when Ramadan starts, then it is not valid even if it happens to be in Ramadan.