If you’ve ever been exhausted, this has likely happened to you: you finally get horizontal, your eyes close, and just as the world begins to slip away, you jerk awake – maybe even into an upright position – as though you’ve seen a ghost or encountered a cattle prod between the sheets.

GIPHY

Credit: GIPHY

This has always been a fairly common occurrence, but without having access to science the way we do now, people in the past ascribed the phenomenon to all kinds of things – even demons choking us as we drift into dreamland.

Current scientists have noticed that this annoying little treat happens most commonly when completely exhausted people fall asleep.

GIPHY

Credit: GIPHY

As you fall asleep, your heart rate and your breathing slow down quickly. But when you’re too tired, this transition can happen so quickly that it startles your body into thinking you’re dying – not sleeping – and it jerks you awake with a quick jolt of chemicals to save your life. Which is kind of sweet, I guess?

Thanks, bod.

This is, however, only a working theory and more study needs to be done. I’m not sure whether there will be funding for that when we also need to like, cure cancer, but you never know.

More from Live Science:

“One hypothesis says that hypnagogic jerks are a natural part of the body’s transition from alertness to sleep, and occur when nerves “misfire” during the process.

Another popular idea takes a more evolutionary approach to hypnic jerks, explaining that the spasms are an ancient primate reflex to the relaxation of muscles during the onset of sleep — the brain essentially misinterprets the relaxation as a sign that the sleeping primate is falling out of a tree, and causes the muscles to quickly react.”

h/t: Diply