Much like childbearing, sleeping is a fundamentally biological process with a lot of culture built around it.
Even the biological part can be treated as fair game for worldbuilding, of course. In the Forgotten Realms shared setting, elves don’t actually sleep; instead they go into a meditative state called “reverie.” From the perspective of a Dungeons & Dragons game taking place in that setting, it’s functionally the same thing — it serves the same purposes in terms of preventing the fatigued state and helping spellcasters regain their abilities — but it’s a different state, and elves need only half as much time spent in reverie as humans and other races do in sleep.
Relatively little of the interplanetary science fiction I’ve read pays much attention to this topic, but it ought to be a common one. Not just as a matter of alien biology: although our sleep cycles are definitely influenced by light, that doesn’t mean you can just rely on a different day-night cycle to shift people onto, say, a 30-hour rhythm and have that work out. Non-24-hour sleep-wake disorder is a condition (much more common among the totally blind, but also sometimes found in the sighted population) wherein a person’s circadian rhythms don’t conform to our planet’s rotation; treating that requires medication and/or light therapy, and even then, it isn’t always successful. Much like populations living at high latitudes, where the variation in daylight between summer and winter is extreme, humans on other planets would likely need to take active steps to function within a different cycle.
Our interaction with sleep also tends to vary with age. Newborn babies sleep a lot, while elderly people often sleep less. But it isn’t just about quantity; there seems to be a natural tendency for teenagers to drift toward a cycle of staying up later and waking later, to the point where a study on scholastic achievement found that high school students whose classes started at 9 a.m. performed noticeably better than those who began at 7. These inclinations can be measured in the 24-hour variation of body temperature, whose peak and trough can be used to predict when a person naturally wants to sleep — so when people declare themselves “early birds” or “morning larks” vs. “night owls,” that isn’t just an expression of preference.
While I was writing A Natural History of Dragons I learned something fascinating (that of course promptly went into the book), which is that in the absence of abundant artificial lighting, the dominant pattern may be for people to sleep in two phases at night, with a period of wakefulness in the middle. I only know of evidence for this in historical writings from the Western world — nothing I’ve seen comments on whether it’s prevalent in non-industrialized communities elsewhere — but there are widespread references in literature to a “first sleep” and a “second sleep,” separated by an hour or two. People spent that interval praying, thinking (often upon their dreams), writing, or having sex; apparently it was also a prime opportunity for committing crimes.
The influence of artificial lighting on our circadian rhythms can be enormous. I have a program called f.lux installed on my computer, which changes the hue of my display after sunset, shifting it away from the blue-tinged light that tells my body it’s still daytime. When you see advice about limiting “screen time” prior to sleep, this is part of the reason why. But it isn’t just electronic devices: light bulbs, gas lighting, and even abundant candles and lamps can help keep us awake long after the point at which we would otherwise have fallen asleep. They not only facilitate us doing work or leisure activities at night, but interfere with the signals that trigger sleepiness.
If you find yourself sleeping during the day, you’re far from alone. “Biphasic sleep” is the term for sleeping twice in a twenty-four hour period (“polyphasic” if it’s more than that), and as the bit above about first sleep and second sleep indicates, that may be entirely natural. When one of the phases happens in daytime, though, we call that a nap — or, when it’s a cultural tradition, a siesta (from the Spanish word for that practice).
Siestas are fairly common in hot countries, though by no means limited to them. In that kind of climate, they’re very good sense: resting in the early afternoon shields you from the the worst heat of the day. There are more general biological reasons why we often want a nap in the afternoon, though, and studies have found evidence that taking one is good for you. A brief period of sleep, perhaps in the 10-20 minute range, can produce significant improvements in alertness, memory, and other aspects of cognitive performance.
Unfortunately for us modern humans, our world is often not set up to allow for naps. The puritanical work ethic that views daytime sleeping as a sign of weakness and moral failure, combined with the corporate drive for constant productivity, results in a situation where napping makes you a bad employee — even if you’d be a better one if you were allowed a few minutes of shut-eye after lunch. In a science fictional future, though, naps might be permitted or even mandated.
There’s actually quite a bit of room in speculative fiction to do interesting things with this subject. Magic or advanced technology could reshape of our biological drive for sleep, e.g. by adapting us to a planet with a 30-hour day — thus creating problems for travelers to or from that planet, who are on the wrong cycle — or remove the need for sleep entirely, as with Nancy Kress’ Beggars in Spain. Any fantasy world that includes magic for rapid travel across long distances could and probably should incorporate the equivalent of jet lag, as the characters’ circadian rhythms go out of sync with the light around them. Your fictional society could have a tradition of siestas, or biphasic sleep at night.
And when you’re writing about non-human creatures, all assumptions might be up for grabs. Do they sleep the way humans do? Are they diurnal (active during the day), or would it be more interesting for them to be nocturnal or crepuscular (active at dawn and dusk)? What about hibernation or its summer cousin, aestivation? Simple changes of this type can go a long way toward making your alien species or fantasy race look like something other than humans with rubber prosthetics on.
Now if you’ll excuse me, I think I’ll go take a nap.