In order to find Biblical information about a topic, it is a good idea to use a Strong's Exhaustive Concordance of the Bible. This wonderful reference book lists every single time a specific word is used in the KJV. So, I looked up the words "fast" and "fasting" in Strong's. Curiously, there are no directions for fasting found in God's Law or in the first five books of the Bible. If fasting had been very important to God, He surely would have given us explicit directions!
It seems people fasted throughout the Bible in order to take their minds off of their bodies and to refocus their minds on spiritual matters. In the Old Testament, there are accounts of people fasting while waiting for an answer to prayer. See Ezra 8:21, 9:5, Nehemiah 1:4, Esther 4:3, 16. Many times people would fast because they had sinned. They used fasting to purify their bodies and to humble themselves before God. See Nehemiah 9:1, Daniel 9:3.
However, Isaiah 58 records God's quarrel with Israel and the manner of their fasting. "…declare to my people their transgression… (Israel said) 'Why have we fasted, and you see it not? Why have we humbled ourselves, and you take no knowledge of it?' (God answers) 'Behold, in the day of your fast you seek your own pleasure, and oppress all your workers. Behold, you fast only to quarrel and to fight and to hit with a wicked fist. Fasting like yours this day will not make your voice to be heard on high. Is such the fast that I choose, a day for a person to humble himself? Is it to bow down his head like a reed, and to spread sackcloth and ashes under him? Will you call this a fast, and a day acceptable to the LORD? Is not THIS the fast that I choose: to loose the bonds of wickedness, to undo the straps of the yoke, to let the oppressed go free, and to break every yoke? Is it not to share your bread with the hungry and bring the homeless poor into your house; when you see the naked, to cover him, and not to hide yourself from your own flesh?" Isaiah 58:1-7
From God's perspective, God wants us to sacrifice our flesh to help the oppressed, to feed the hungry, to help the homeless, etc. Denial of the flesh through fasting and to sit in sackcloth and ashes (which was the custom) doesn't impress God.
However, Jesus, Himself, fasted for forty days in the wilderness. In this account, it does not say why Jesus fasted. He was not fasting due to sin or to wait for an answer to prayer. No, probably Jesus abstained from food due to His intense communion with His Father. Jesus was preparing for His ministry and it's reasonable to believe He was focusing on the details of how He was going to sacrifice His life as a ransom for all. (1 Tim. 2:6)