For as long as I can remember I've heard a loud noise just before falling asleep, not every night, but every few days. Usually the noise is so loud that I instantly wake up. It then takes a while before I fall asleep again, this time without hearing a loud noise. On rare occasions I hear another loud noise the second time I fall asleep.
The noise is typically accompanied by a dream image. Thus, what I hear is an explosion, a balloon popping, a thunder clap, a gun shot, something falling and hitting the floor, a door slamming shut, whether a front door or the door of a car and so on. Occasionally I also see rapid flashes of light.
A few years ago I learned that there is a name for this phenomenon: exploding head syndrome. I never thought of myself as having a syndrome, because I don't recall not hearing the noise every once in a while. The cause of the symptom is still unknown. Various hypotheses have been put forward, but researchers still grope in the dark.
I may be in good company. The French philosopher René Descartes (1596-1650) famously reported having three successive dreams in the night of 10 November 1619 that provided him with a mission in life: to reform all knowledge, beginning with philosophy. After lying awake for two hours following his first dream, just as he fell asleep, Descartes "had a new dream in which he believed he heard a sharp and shattering noise, which he took for a clap of thunder. The fright it gave him woke him directly, and after opening his eyes he perceived many sparkling lights scattered about the room. The same thing had often happened to him at other times…"
Otaiku A. I. (2018). Did René Descartes Have Exploding Head Syndrome?. Journal of clinical sleep medicine : JCSM : official publication of the American Academy of Sleep Medicine, 14(4), 675-678.
Sharpless B. A. (2014). Exploding head syndrome. Sleep Medicine Reviews, 18(6), 489-493.