If you've ever found it difficult to get a good night's rest in a strange environment like a hotel room or a new house, you're not the only one. The 'first night effect' is something sleep scientists are well aware of, and it's a factor they have to allow for when they're studying sleep – often by discarding people's data from the first night in sleep experiments, when they're monitored away from home in the lab.

But what's actually causing the first night effect to take place? According to a new study, we sleep poorly in unfamiliar environments as a kind of defence mechanism. While we're resting – or trying to, that is – it seems one hemisphere of the brain remains more awake than it usually would, in a kind of cerebral equivalent of sleeping with one eye open to ward off potential dangers.

"If we don't know whether a room is safe to sleep in, then we will have this night watch system so we can detect anything unusual," sleep scientist Masako Tamaki from Brown University told Ian Sample at The Guardian. "It's like a safeguard."

To figure out what contributes to this restlessness in new environments, the researchers studied the sleep of 35 volunteers. Over the course of two nights in the lab, a week apart, the scientists used electroencephalography, magnetoencephelography, and magnetic resonance imaging to monitor the participants' brain activity.

On the first night, the team found the would-be sleepers consistently showed greater activity in the left hemisphere of their brains than in the right. This heightened activity in the left hemisphere was particularly evident during deep sleep, in a sleep phase called 'slow-wave' sleep. This activity makes us more prone to waking, which the team demonstrated by playing irregular beeping sounds to the participants.

When they played these sounds in the right ear of the sleepers – stimulating the left hemisphere – the volunteers showed a greater likelihood of waking. They also woke more quickly than when the right hemisphere was stimulated (via sounds played in the left ear).

I know what you're thinking – as if these poor people didn't already have enough to deal with, spending the first night in a strange lab, without having scientists deliberately administering subtle sonic torture!

On the first night, other sleep phases (apart from slow-wave sleep) didn't indicate any heightened activity or alertness in either hemisphere – despite all the same monitoring instruments being in place. And it seems the group had adapted to their lab bunks by the time they spent their second night there, suggesting that the first night effect is indeed limited to the first night, and only takes place in the left hemisphere during slow-wave sleep.

"To our best knowledge, regional asymmetric slow-wave activity associated with the first-night effect has never been reported in humans," the researchers report in Current Biology.

The team acknowledges there's still more to be discovered about the extent of the first night effect. After all, this is only a fairly small trial with a small group of participants, and in the experiment, they only monitored the first phase of slow-wave sleep. It's possible that during subsequent phases, the site of the brain's built-in watchfulness could shift internally, which is something that's been observed before in animals, such as dolphins.

"There's certainly a possibility that the vigilant hemisphere changes over the night," Tamaki told The Guardian.

Confirming that particular hypothesis will have to be left for future research, but until that time, at least we now know why we feel so grouchy after a poor night's sleep in a new place.

And we should really be thankful, I guess – it is just our body's way of making sure we're safe at night. At least there's always coffee, right?