(WHTM) — Halloween has been synonymous with pumpkin carving, dressing up in fun costumes, and trick or treating.

But why does trick or treat exist, and what does it have to do with Halloween?

It has some of its roots with the Samhain which was an ancient Celtic festival that was first celebrated around 2,000 years ago. The Farmers Almanac said that this holiday is where Halloween first comes from.

During Samhain, which would be held on Oct. 31, it was thought that ghosts of the dead returned to the world, and could cause havoc on those who were still living, such as ruining crops and causing chaos. To combat this, people would dress up in costumes and set up elaborate tables with a feast to make an offering to them and drive the ghosts away.

During the Middle Ages, people were still dressing up for the holiday, but they dressed up as ghosts, demons, and other creatures. The Farmers Almanac said that instead of banquets to appease the angry ghosts, performances were held instead. This new tradition was called mumming.

These ‘mummers’ would go door to door, singing and dancing for food and drink. In the Middle Ages, mumming did not just occur for Halloween, but also for Christmas and Easter.

By the ninth century, Christianity made its way into the Celtic regions and blended with pagan ceremonies. In the year 1000 A.D., All Souls Day was designated by the Christian Church as a way to honor the dead. This was done by bonfires and other celebrations.

Poorer people would visit the houses of richer people and receive pastries in exchange for promising to pray for the souls of the homeowner’s dead relatives. This was known as ‘souling’ and was later practiced by children, according to History.com.

Fast forward to the late 19th century. The Farmers Almanac said All Souls Day had gone through a name change, becoming All-Hallow’s Eve, and finally, Halloween. The tradition of ‘souling’ was brought to the United States during that time, but it was problematic in the beginning.

Farmers Almanac said that kids would use the holiday as a way to prank people or cause property damage. It wasn’t until the time around the Great Depression that the term ‘trick or treat’ came about.

While Halloween was known as a time when pranksters ran around, it was also seen as a time for kids to collect treats. Kids would ask, “Trick-or-treat?” when they would visit homes, giving homeowners a choice of either being tricked, pranked, or giving out the treats. Most homeowners didn’t want to be pranked, so they gave out sweet treats and candy.

From then on, trick-or-treating became a tradition. The only time it was not performed was during World War II when there was a sugar ration. But after the war, and to this day, it’s hard not to see costumed children going door to door looking for that sweet treat.