On National Doughnut Day on Friday, the sweet treat’s biggest fans will celebrate by taking advantage of doughnut shops’ deals for free or discounted goods, while police departments will inevitably poke fun at this “national holiday for police officers” on social media.

By now, the stereotype of the doughnut-loving cop is well-established — but how did it start?

The short answer is that police officers have long worked odd hours, but the options for food in the wee hours haven’t always been plentiful. The option to pick up a doughnut dates to the years after World War II.

“Graveyard cops in the forties and fifties had few choices. They could pack lunch, pray for an all-night diner on their route or fill up on doughnuts,” Norm Stamper, the former chief of the Seattle Police Department, says in The Donut: History, Recipes, and Lore from Boston to Berlin by Michael Krondl. “They were cheap and convenient.” Former Baltimore City police detective Dick Ellwood likewise recalled being allowed to just eat doughnuts off the assembly line shortly after the shops opened in the wee hours of the morning.

Get our History Newsletter. Put today's news in context and see highlights from the archives. Please enter a valid email address. Sign Up Now Check the box if you do not wish to receive promotional offers via email from TIME. You can unsubscribe at any time. By signing up you are agreeing to our Terms of Use and Privacy Policy . This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply. Thank you! For your security, we've sent a confirmation email to the address you entered. Click the link to confirm your subscription and begin receiving our newsletters. If you don't get the confirmation within 10 minutes, please check your spam folder.

“The early-hours doughnut shop is a post-World War I phenomenon in major cities and did not spread to most of the remainder of the country until after World War II, so the stereotype of an overweight officer drinking burnt coffee and eating a glazed doughnut is a relatively recent creation,” Paul Mullins, a professor of Anthropology at Indiana University-Purdue University, Indianapolis, and author of Glazed America: A History of the Doughnut, told TIME in an email.

In addition, he pointed out, it matters that doughnuts are cheap: cops aren’t supposed to accept any free gifts while on duty, so it makes sense that they’d decide to spend their own snack money on something affordable.

And, especially at those odd hours of the night, the doughnut shops actively tried to entice police officers to stop in for a snack. In his autobiography, Dunkin’ Donuts founder William Rosenberg claimed he wanted to make sure franchises were “hospitable places for the police” who “protected the stores.”

As late-night food options expanded, police came to be able to eat other things, but the joke stuck.

Write to Olivia B. Waxman at olivia.waxman@time.com.