Sleep is a surprisingly active process. You probably do nearly as much while you sleep as you do during the same period of being awake. When you go to sleep, your body begins a period of active repair and reconfiguration, adjusting and fixing damage and other problems in the body, while the mind processes, sorts, organises and makes sense of all that has been seen and done during the day. It is from surfacing to consciousness through this cacophony of ideas, feelings and senses that dreams emerge. This article by BBC Future describes the process of sleeping in more detail.
Sleep is necessary to functioning properly while you are awake, regulates the immune system to keep you well and reaffirms your in-built day-night rhythm of sleeping and waking. Rising levels of the sleep hormone melatonin make deeper sleep easiest around midnight, while strong light such as morning sunlight falling on the eyes (even through closed eyelids!) stimulates the pineal gland causing sensations of wakefulness. Everyone’s preferred working rhythm therefore varies to some extent but it seems to be that we all have an optimal time to be asleep, from between six and nine hours (averaging about 7.5 hours) a night, spanning midnight.
Back in Tudor times people would sleep for 4-5 hours a then woke about 2 am to converse, visit friends, snack, read or play quiet games before retiring for another few hours sleep. Relatively inexpensive electric lighting and more comfortable beds mean we can more easily get the same benefit in under two-thirds the time but research suggests both methods work about as well. What seems to matter more is having regular times that you sleep in a dark, cool and comfortable room with calming rituals that lead up to bedtime. Avoid stimulation, including glaring screens, caffeinated drinks and intensive exercise in the run-up to bedtime, keep a notepad to jot down things to remember or deal with in the morning, put everything beyond your immediate control past caring and allow your body to relax.
If you are consistently having trouble sleeping, you should speak to your GP or the University Wellbeing Service.