It is a very important question that why do we fast in Ramadan or in any other opportunity.Allah(the creator) had told us about that in a sufficient answer in the holy Quran: says( O you who believe! Observing As-Saum (the fasting) is prescribed for you as it was prescribed for those before you, that you may become Al-Muttaqûn (the pious – See V183).
A) Narrated Talhah bin ‘Ubaidullâh: A bedouin with unkempt hair came to Allâh’s Messenger صلى الله عليه وسلم and said, “O Allâh’s Messenger! Inform me what Allâh has made compulsory for me as regards the Salât (prayers).” He replied: “You have to offer perfectly the five compulsory Salât (prayers) in a day and night (24 hours), unless you want to pray Nawâfil .” The bedouin further asked, “Inform me what Allâh has made
compulsory for me as regards Saum (fasting).” He replied, “You have to fast during the whole month of Ramadân, unless you want to fast more as Nawâfil .” The bedouin further asked, “Tell me how much Zakât Allâh has enjoined on me.” The narrator added: Then, Allâh’s Messenger صلى الله عليه وسلم informed him all about the Laws (i.e. fundamentals) of Islâm. The bedouin then said, “By Him Who has honoured you, I will neither perform any Nawâfil nor will I decrease what Allâh has enjoined on me.” Allâh’s Messenger صلى الله عليه وسلم said, “If he is saying the truth, he will succeed (or he will be granted Paradise). (Sahih Al-Bukhâri, Hadîth No.115, Vol.3).
(B) Narrated Abû Hurairah رضي الله عنه: Allâh’s Messenger صلى الله عليه وسلم said, ” As-Siyâm (the fasting) is Junnah (protection or shield or a screen or a shelter from the Hell-fire*). So, the person observing Saum (fasting) should avoid sexual relation with his wife and should not behave foolishly and impudently, and if somebody fights with him or abuses him, he should say to him twice, ‘I am fasting.’ ” The Prophet صلى الله عليه وسلم added, “By Him in Whose Hands my soul is, the smell coming out from the mouth of a fasting person is better with Allâh تعالى than the smell of musk. (Allâh says about the fasting person), ‘He has left his food, drink and desires for My sake. The Saum (fast) is for Me**. So I will reward (the fasting person) for it and the reward of good deeds is multiplied ten times.’ ” (Sahih Al-Bukhâri, Hadîth No.118, Vol.3).
* See Fath Al-Barî , Vol.5, Page 5.
** Although all practices of worshipping are for Allâh, here Allâh تعالى singles out Saum (fasting), because fasting cannot be practiced for the sake of showing-off, as nobody except Allâh can know whether one is fasting or not. Therefore, fasting is a pure performance that cannot be blemished with hypocrisy. (Fath Al-Barî, Vol.5, Page 10)
(C) Narrated Abû Hurairah رضي الله عنه: The Prophet صلى الله عليه وسلم said, “Whoever does not give up lying speech – false statements (i.e. telling lies) and acting on those (lies), and evil actions etc., then Allâh is not in need of his leaving his food and drink (i.e. Allâh will not accept his fasting*)”. (Sahih Al-Bukhâri, Hadîth No.127, Vol.3).
* See Fath Al-Barî , Vol.5, Page 18.
 (V.2:186) Narrated Abu Hurairah رضي الله عنه: Allâh’s Messenger صلى الله عليه وسلم said, “Allâh said, ‘I will declare war against him who shows hostility to a pious worshipper of Mine. And the most beloved things with which My slave comes nearer to Me, is what I have enjoined upon him; and My slave keeps on coming closer to Me through performing Nawâfil (praying or doing extra deeds besides what is obligatory) till I love him. Then I become his sense of hearing with which he hears, and his sense of sight with which he sees, and his hand with which he grips, and his leg with which he walks; and if he asks Me, I will give him, and if he asks My protection (Refuge), I will protect him; (i.e. give him My Refuge), and I do not hesitate to do anything as I hesitate to take the soul of the believer, for he hates death, and I hate to disappoint him.” (Sahih Al-Bukhâri, Vol.8, Hadîth No. 509).Through the previous explanation it shows that fasting
is a strong element for getting the pious.The one who gain pious ,he will fear allah where ever he was without performing any thing wrongly.So pious is a safe boat not only in life but after death.