What's the story behind the Hungry Ghost Festival?

There are many legends about Chinese Hungry Ghost Festival and the main three are as follows:

Chinese Folk Legend
According to the Chinese folk legend, the gate of hell is wide open on July 15 in Chinese calendar and ghosts would come out on this day. Those who are offered sacrifices come back to the hometown to accept the worship of descendants while Buddhist or Taoist rituals are held by the public to worship the lost spirits and ghosts to keep them from wandering around and harming the living beings.

Legend of Zhongyuan Festival by Taoism
The Ghost Festival is called Zhongyuan Festival by Taoism. Taoism believes the name of Zhongyuan Festival is originated from Northern Wei Dynasty (368-534). According to the ancient books, the lunar January 15 is the Lantern Festival, a blessing day of the Heaven King; the lunar July 15 is the Ghost Festival, a pardon day of the Hell King while the lunar October 15 is the Water Lantern Festival, a disaster relief day of the Water King. On lunar July 15, the birthday of Hell King, the hungry ghosts and imprisoned spirits are pardoned and released from the hell to accept the rituals and sacrifices for one month since July 1 in the mortal world, so as to motivate them to practice Taoism. Through the sacrifice ceremony and rites, Taoist followers assist the Hell King to release souls from purgatory early and keep them from causing troubles to the realm of the living. Therefore, the Taoists chant sutras, hold rituals and offer sacrifices to release the suffering spirits from purgatory, while the folk people worship the Hell King and their ancestors with rich sacrifices.

Buddhist Legend: Mulian Rescues His Mother
Yu Lan Pen Festival is what Buddhists call to the Chinese ghost festival. A Buddhist legend about the festival goes that, when Buddha Shakyamuni was still alive, one of his ten disciples named Mulian (Maudgalyayana) cultivated and got enlightenment, becoming an Arhat with miraculous powers. His parents died early before this. To repay the birth of his parents, he observed with the deva eyes and found his dead mother in the realm of hungry ghosts and she had no food and looked skinny. Maudgalyayana was sorrowful and he used the miraculous power to offer a bowl of rice to his mother. When she was about to eat, the food suddenly changed to ash. Extremely grieved, he came to Buddha Shakyamuni and told the Buddha what happened. The Buddha inspired him: ''your mother was guilty of many sins when she was alive, so she has to be a hungry ghost and suffer a lot. You cannot release her with your own strength but the power of monks in ten directions. Every year, all the monks cultivate together from April 15 to July 15 and on the last day, there must be many who get enlightenment. If you want to release your mother from the realm of hungry ghosts, you should offer all kinds of good vegetarian food to them, and this will be a good deed which can release your mother from the realm of hungry ghosts, benefit your parents in the last seven lifetimes and prolong their life if they are still alive.''

Maudgalyayana followed what the Buddha Shakyamuni said and released his mother from the sufferings. Later, a folk custom is formed according to the legend and gradually evolves from making offerings to monks to ghosts. In every lunar July, Chinese people would kill chickens and ducks, and burn incense and clothes to worship the hungry ghosts and dissolve their grievances, so that they no longer cause trouble to the mortal world. Over time, the Ghost Festival is formed.

Related Reading: 
→ Ghost Month
→ Can You Move House During Ghost Month?
→ Can You Get Married During Ghost Month?
→ Taboos to Avoid during Hungry Ghost Month

Chinese Calendar

SuMoTuWeThFrSa
29廿七/27 30廿八/28 1廿九/29 2三十/30 九月 (Sep) 3初壹/1 4初二/2 5初三/3
6初四/4 7初五/5 8初六/6 9初七/7 10初八/8 11初九/9 12初十/10
13十壹/11 14十二/12 15十三/13 16十四/14 17十五/15 18十六/16 19十七/17
20十八/18 21十九/19 22二十/20 23廿壹/21 24廿二/22 25廿三/23 26廿四/24
27廿五/25 28廿六/26 29廿七/27 30廿八/28 31廿九/29 十月 (Oct) 1初壹/1 2初二/2