Hypnagogia:
Hypnagogia is the transitional state from wakefulness to sleep, also defined as the waning state of consciousness during the onset of sleep. Its opposite state is described as hypnopompia – the transitional state from sleep into wakefulness. Mental phenomena that may occur during this “threshold consciousness” phase include hypnagogic hallucinations, lucid dreaming, and sleep paralysis. [Wikipedia]
Noted in “Fresh insights into how we doze off may help tackle sleep conditions,” Graham Lawton, NewScientist (26 October 2024, paywall):
Researchers – and most people – have long been aware that there is more to the transition into sleep than a simple on-off switch, says [cognitive neuroscientist Delphine Oudiette at Sorbonne University], in part because of a bizarre, semi-lucid state at the onset of sleep called hypnagogia, featuring hallucinatory, dream-like experiences.
Your brain shutting down is an inefficient and bio-soggy process.