It’s almost that time of year when underaged kids get into costume and traipse around the neighborhood ringing doorbells and begging for treats. When you think about it, trick or treating is kind of a weird thing. Where did it come from anyway?

Today I Found Out discovered that the practice began with the Celtic tradition of celebrating the end of the year by dressing up as evil spirits. The Celts believed that, as we moved from one year to the next, the dead and the living would overlap, and demons would roam the earth again. So dressing up as demons was a defense mechanism. If you encountered a real demon roaming the Earth, they would think you were one of them.

Fast forward to when the Catholic Church was stealing everybody’s holidays and trying to convert them. They turned the demon dress-up party into “All Hallows Eve,” “All Soul’s Day,” and “All Saints Day” and had people dress up as saints, angels and still a few demons. Today I Found Out writes:

As for the trick or treating, or “guising” (from “disguising”), traditions, beginning in the Middle-Ages, children and sometimes poor adults would dress up in the aforementioned costumes and go around door to door during Hallowmas begging for food or money in exchange for songs and prayers, often said on behalf of the dead. This was called “souling” and the children were called “soulers”.

You might think that this practice then simply migrated along with Europeans to the United States. But trick or treating didn’t re-emerge until the 1920s and 1930s. It paused for a bit during World War II because of sugar rations, and it’s now back in full force.

The term “trick or treat” dates back to 1927. Today I Found Out explains:

The earliest known reference to “trick or treat”, printed in the November 4, 1927 edition of the Blackie, Alberta Canada Herald, talks of this, Hallowe’en provided an opportunity for real strenuous fun. No real damage was done except to the temper of some who had to hunt for wagon wheels, gates, wagons, barrels, etc., much of which decorated the front street. The youthful tormentors were at back door and front demanding edible plunder by the word “trick or treat” to which the inmates gladly responded and sent the robbers away rejoicing.

The British hate Halloween, apparently. In 2006, a survey found that over half of British homeowners turn off their lights and pretend not to be home on Halloween. Yet another reason by the United States is happy to be free from British rule. No funs.

More from Smithsonian.com:

Wednesday Roundup: Phantoms, Costumes and Halloween Galore

Halloween Costume Ideas from the Collections