The command to fast has been given in detail in the Quran. We quote here the relevant verses:
Fast for a specified number of days, but if any one of you is ill, or on a journey, let him fast the same number of days later. For those who can fast only with extreme difficulty, there is a way to compensate — the feeding of a poor man. But he who does good of his own accord shall be well rewarded; but to fast is better for you, if you only knew.
The month of Ramadan is the month when the Quran was sent down as guidance for mankind with clear proofs of guidance and the criterion by which to distinguish right from wrong. Therefore, whoever of you is present in that month let him fast; but he who is ill or on a journey shall fast a similar number of days later on. God desires ease for you; He desires you to fast the whole month, so that you may magnify Him for His having guided you, and so that you may be grateful to Him.
And when My servants ask You about Me, say that I am near; that I respond to the call of one who calls, whenever he calls to Me: let them, then, respond to Me, and believe in Me, so that they may be rightly guided.
It is made lawful for you to go to your wives on the night of the fast: they are like a garment for you, and you are like a garment for them. God is aware that you were deceiving yourselves and He has turned in mercy towards you and pardoned you. So you may now consort with them and seek what God has ordained for you; now you can lie with them — seek what God has ordained for you — eat and drink until the white thread of dawn becomes distinct from the black. Then fast until nightfall. These are the limits set by God, so do not approach them. Thus He makes clear His commandments to mankind, that they may guard themselves (against evil). (2: 184-187)
This is the basic commandment regarding fasting. It has been further elaborated upon in the Hadith and the Fiqh.
In the books of Hadith, several traditions have been collected under the chapter sawm, which show different aspects of the rite of fasting.
The traditions tell us that when the month of fasting approached, the Prophet gave a sermon in which he described the importance of fasting in this month. Hazrat Ali, the Prophet’s cousin, and one of the early converts to Islam, has narrated that after the sermon, he stood up and said, “O Messenger of God, —Which action is best in this month?” The Prophet replied, “O Abul Hasan (his nickname), the best action in this month is to guard oneself against prohibited things”. This tradition tells us about the actual spirit of fasting, which is to abstain from all those things that God has forbidden. The command to refrain from taking food and drink during the month of Ramzan is, in fact, a practical lesson in doing so. Food and water are the last things that one may be asked to refrain from. Putting a curb on man’s basic necessities is to give a strongly worded lesson—that the things God has forbidden you must be eschewed, however contrary that might be to your tastes and habits. This should be done, even if that involves doing without your most basic requirements.
Another tradition is recorded in these words: “The Prophet of Islam said that when a person who was on a fast was abused, he should say in return, “Peace be upon you, I am not the one to return abuse for abuse.” For such a person God has this to say: “My servant took refuge in fasting for someone’s evil; so I also gave him refuge from hellfire.”
The goal of fasting is to develop in man the ability to lead his life bound by restrictions, rather than lead a totally unfettered life.