Jesus, full of the Holy Spirit, left the Jordan and was led by the Spirit into the wilderness, where for forty days he was tempted by the devil. He ate nothing during those days, and at the end of them he was hungry. The devil said to him, “If you are the Son of God, tell this stone to become bread.” Jesus answered, “It is written: ‘Man shall not live on bread alone.’” (Luke 4:1-4)
Fasting is when we stop eating food for a set period of time in order to focus our time and attention on prayer and the presence of God. It's a way of humbling ourselves before God and declaring our great need for him. It also trains us to consume less than what we want, to say "no" to ourselves, to seek God and love God even when we don't feel full, and to worship God even when we're unsatisfied. Fasting teaches us to live with less even when our bodies are screaming "I want more!"
There are so many reasons to fast, and so many seasons of life that could trigger the need for a fast. Generally, it's helpful to develop a regular rhythm of fasting. Perhaps a weekly 24 hour fast, and a couple of annual multi-day fasts. Additionally, when you have a great need, or a significant prayer request, fasting is an excellent way to go deeper in prayer.
“Fasting confirms our utter dependence upon God by finding in him a source of sustenance beyond food.” (Dallas Willard)