Many Catholics from an older generation will remember the "midnight fast." It meant that one could not eat before Mass starting from the midnight before. For this reason Masses were generally celebrated at dawn and Masses in the evening were extremely rare. Few people wanted to fast all day long before attending Mass and receiving Holy Communion.
This practice of fasting before Mass is an ancient discipline, present as early as the 2nd century. It remained in place until Pope Pius XII reduced the fast to three hours in 1957. The fast was further shortened in 1964 when Pope Paul VI lowered it to one hour before reception of Communion.
The current Code of Canon Law reflects this change and states, "A person who is to receive the Most Holy Eucharist is to abstain for at least one hour before holy communion from any food and drink, except for only water and medicine" (Canon 919 §1).
However, in some cases those rules do not apply. "The elderly, the infirm, and those who care for them can receive the Most Holy Eucharist even if they have eaten something within the preceding hour" (Canon 919 §3).
But why? What does it matter if I ate a cheeseburger right before I walked into church on a day I intend to receive the Holy Eucharist?
Pope Paul VI wrote concerning the power of spiritual discipline in his apostolic constitution Paenitemini: "Mortification aims at the liberation of man, who often finds himself, because of concupiscence, almost chained by his own senses. Through 'corporal fasting' man regains strength, and the wound inflicted on the dignity of our nature by intemperance is cured by the medicine of a salutary abstinence."
Jesus knew the power of fasting and went into the desert without food for 40 days before setting out on his public ministry. Furthermore, he taught his disciples that, "This kind [of demon] cannot be driven out by anything but prayer and fasting" (Mark 9:29).
Fasting builds up our spiritual strength, and the Church asks us to complete this simple task every time we receive Holy Communion for our own benefit. Just like any athlete we need to exercise discipline and fasting is great for building those spiritual muscles. Without fasting we are weak and our passions drive us to wherever the wind blows.
Additionally, Pope John Paul II lamented in Dominicae Cenae how modern Catholics possess a "lack of Eucharistic 'hunger' and 'thirst,' which is also a sign of lack of adequate sensitivity towards the great sacrament of love and a lack of understanding of its nature." We need to "hunger" and yearn for the Eucharistic before we can properly receive it. Our reception of Holy Communion needs to correspond to an inner hunger that is indicative of a soul that thirsts for God's love. If we don't have this hunger (brought to mind by our physical hunger during fasting), we might think of Holy Communion as something ordinary, not needing any preparation beforehand.
Last of all, fasting before Mass is an image of the Eucharistic stories in the Gospels, specifically the Feeding of the Five Thousand. After a long day the disciples urged Jesus to send the crowd away so that they could buy food for themselves to eat. Instead, Jesus multiples the bread and fish, leaving everyone "satisfied" at the end of the meal. Just like the crowd on that day, when we approach the table of the Lord we must be hungry, or as the Psalmist proclaims, "As a hart longs for flowing streams, so longs my soul for thee, O God" (Psalm 42:1).