Are you listening to your body clock?

This page was originally developed for the University of Surrey's exhibit "The Science and Secrets of Sleep" for Universities Week 2014 at the Natural History Museum in London. It has since been updated to reflect our latest work on the timing of sleep and circadian rhythms. For further information on research carried out on sleep and the body clock please visit the Surrey Sleep Research Centre.

We often override the natural rhythms of our body clock and stay awake when our body clock is telling us to sleep, and are woken by an alarm before we are ready to get up. There is increasing evidence that living out of sync with our body clock is bad for our health.

To help explain how our body clock determines when we feel sleepy and when we are alert, we have produced a freely downloadable program for the most widely used model of sleep/wake regulation (known as the "two-process model"). The program includes an interactive interface that you can use to determine whether or not your pattern of bedtimes and wake times is in tune with the body clock of the average person of your age.

Downloading the model

How to use the model

Things to notice

What else to try

The science behind the model

What if it doesn't describe my sleep patterns?

Credits and references

Downloading the model

The model is written for the Netlogo programmable environment, so if you don't already have Netlogo then you must first install it. It is freely available from here.

Netlogo is designed to be an easy environment for the non-expert to run (and create) models of a wide variety of different phenomena - the Netlogo Models Library website gives a large number of examples. Netlogo is easy to download and install and runs on windows, linux or mac's. The sleep models were coded up to run on Netlogo 5.2.

Our Netlogo model of sleep/wake regulation model can be downloaded by right clicking here and click on "Save link as..."

Note that this first version is set up to run over four days. A seven day version is available here. This `wraps round' so that you can look at weekly patterns of behaviour.

How to use the model

  1. Once you have downloaded Netlogo and the sleep-wake regulation code (see the previous section), then start up the model by either (i) double-clicking on the file SleepWakeRegulation.nlogo or by starting Netlogo and using the open option (found under File) to find the SleepWakeRegulation.nlogo file on your computer.
  2. Use the cursor to move the age slider to the age you are interested in.
  3. Set whether the model is running according to the body clock or not by clicking just below the words "Listening-to-your-body-clock and selecting either Yes or No.
  4. If you have set the model to not listen to your body clock, then set up the wake and sleep times at the top of the main window.
  5. Note that for each day, time is counted from 0 at midnight onwards, as in the normal 24 hour clock. So, for example, if you want to set the model to go to sleep at 11pm on Sunday night, then you set the time Sun_sleep to 23. What do you do if you stayed up later and instead went to bed at 2am on Monday morning? You cannot enter 2, as this would mean 2am on Sunday morning. Instead, set Sun_sleep as 26, that is 2 hours on from 24.

  6. Click on the setup/clear screen.

    You should see a row of suns and stars and some vertical grey bands. The horizontal axis indicates time, and runs from midnight on Sunday through to midnight on Wednesday. The suns and stars indicate the position of midday and midnight for each day. The grey bands indicate the times of sleep, as set by the buttons Sun_sleep, Mon_wake etc.

  7. Click on the go/stop button.

    You should see two lines move across the page: the grey line oscillates up and down in an approximately regular way, this represents the daily rhythm of your body clock. The black line is more of a saw-tooth shape. This is known as the sleep pressure: it increases when you are awake and decreases when you are asleep.

Things to notice

The black line goes up when you are awake and down when you are asleep.

If you run the model in the "listening to your body clock" mode, then the times the model falls asleep and wakes up are determined by the times that the two different bio-rhythms meet.

If you run the model in the "not listening to your body clock" mode, then the wake up and go to sleep times are fixed by the times you have set in the boxes and shown by the grey shaded regions. You may now see that the biorhythms change colour from black to red or from black to yellow. The red parts correspond to times when your body clock is telling you that you really want to be asleep, but you are awake. The yellow parts correspond to times when your body clock is telling you that you should be awake, and yet you are trying to sleep.

The times when you are feeling sleepy are also shown in the plot of alertness. Alertness is measured by how widely separated the circadian and sleep pressure rhythms are. Regions of "negative" alertness are shaded in red and correspond to points when your natural body rhythm is telling you that you should be asleep.

What else to try

Once you have run the model with one setting of the sliders, you can run the model again with a different setting by changing the sliders and then clicking on "Re-start". This will plot the new rhythms without clearing the screen. If you want to clear the screen, then press "Set-up".

Try setting the sleep and wake times so that you stay up all night on Sunday night. What does the model say about how you should feel on Monday during the day?

If you fly to a different part of the world, then the times that your body wants to sleep are not the same as the times that societal pressures say that you should sleep. You can see the impact of this by changing the jetlag button from zero. Putting in a positive value of five is like moving East to a time zone that is five hours ahead of us; putting in a value of minus five is like moving West to a time zone that is five hours behind us. Note that the adaptation that our bodies make to a new time zone is not included in this version of the model: in real life, the effects of jetlag diminish after a few days because our body clock shifts to be in tune with the day-night (light-dark) cycle of our new location.

There are two buttons, one labelled wake_timeconstant and one labelled sleep_timeconstant. These describe how quickly sleep pressure builds up during wake and dissipates during sleep. What happens if you make these smaller, say about 6 and set the "Listening to your biology" to Yes? You should see that there are now multiple sleep episodes each day. Any idea what this could describe?

The science behind the model

Biologists believe that there are two fundamental biorhythms or processes that underly sleep/wake regulation. These are:

The most influential model of sleep-wake regulation to-date has been the two-process model that takes the circadian process and the homeostatic process and uses them to describe the timing of sleep and wake [1]. The idea is that the longer we are awake the higher the sleep pressure. If we are listening to our bio-rhythms and going to sleep when we feel sleepy then we fall asleep when the sleep pressure reaches an upper threshold value. How sleepy we feel depends on how far from the upper threshold we are. During sleep, sleep pressure decreases until we reach a lower threshold, at which point we wake up. The upper and lower thresholds are modulated by a 24 hour cycle, mimicking the effect of the circadian process.

Of course, one important fact about sleep is that we are able to over-ride our bodies cues and remain awake even when we are tired, or get up before we have had adequate rest. Historically, this was important for survival, enabling us to adapt our sleep patterns according to our environment. These days, many of us abuse this ability and live in a state of chronic sleep deprivation.

Sleep patterns also change systematically with age. Babies have multiple short sleeps during the day, gradually reducing their number of daily sleep episodes until, by school age, many have dropped their day time sleeps altogether. Living in our modern light environment teenagers typically wake up late and go to bed late, making getting up for school challenging. As we age, sleep becomes shorter, we wake up earlier and sleep becomes more fragmented. These systematic changes with age mean that in our modern urban environment we tend to shift from being more "owl-like" as a teenager to more "lark-like" as we get older. Light plays a key role here, and for a discussion on the effect of our light environment see [6].

The model shows the homeostatic process and the circadian modulated thresholds that cause switching and how they evolve with time over a sequence of 4 days. For clarity, only the upper threshold is shown during wake and the lower threshold during sleep. These can be viewed as representing the two different biorhythms: the homeostatic rhythm and the circadian rhythm.

You can select whether or not the sleep-wake cycle is following the body clock. If the body clock is followed, then switching between wake and sleep occurs when the two different rhythms meet. If the body clock is not followed, then switching between wake and sleep occurs at the times set by the boxes at the top of the display, labelled as Sun_wake, Sun_sleep etc. The selected times are shaded in light grey in the main display window.

There are systematic changes in sleep with age. It is not known exactly what changes occur in the body to cause these changes: but there is some evidence that as we get older the circadian and homeostatic processes weaken. Within this NETLOGO model, changing the age slider does three things (i) reduces the amplitude of the circadian oscillation (ii) reduces the mean value of the upper threshold which is equivalent to reducing the strength of the homeostatic process (iii) the phase of the circadian rhythm compared with the light/dark cycle changes. The motivation for the particular way in which these changes occur in the simulation comes from comparing experimental data on timing of sleep across the lifespan [2] with a mathematical model of sleep-wake regulation constructed by Phillips and Robinson [3], see [4] for more details. Although the Phillips and Robinson model is more sophisticated than the two process presented in this Netlogo model, nevertheless it has many of the same features and the two can be related in a systematic way, see [5].

What if it doesn't describe my sleep patterns?

This particular model is set up to fit one particular measure of sleep, mid-sleep on free days, for an average population living in a modern urban environment. Mid-sleep on free days is the time of the middle of your sleep on a day that you could choose when you went to bed and when you got up. So, for example, if you went to bed at midnight and got up at 10am, then your mid-sleep would be 5am. There are, in fact, systematic differences between men and women and also large individual differences. For example, for any one age group, the mid-sleep on free days reported in [2] varied by two hours; even more for adults over 70. One of the challenges for sleep researchers is taking account of this individual variability.

Another feature of this particular simulation is that it is assumed that you wake up naturally on Sunday morning at the time given by Sun_wake. Of course, this might not have been the case. It would be possible to extend the model to run for more days and typically, if you follow the same daily pattern of when you go to bed and when you get up, then your sleepiness/alertness will settle in to a regular pattern over a period of a week or so.

Credits and references

This netlogo model was coded by Anne Skeldon and is based on the two process model discussed in [1], with changes with age as described in [4]. For further information, please contact

For further information on research conducted at the University of Surrey on sleep and circadian rhythms visit the Surrey Sleep Research Centre.

[1] S. Daan, D.G. Beersma and A.A. Borbely (1984) "Timing of human sleep: recovery process gated by a circadian pacemaker", Am. J. Physiol, 246, R161-83.

[2] T. Roenneberg et al (2012) "A marker for the end of adolescence", Current Biology, 14 pR1-38-R1039 [web address ](

[3] A.J.K. Phillips, P.Y. Chen and P.A. Robinson (2010) "Probing the mechanisms of chronotype using quantitative modelling", J. Biol. Rhythms, 25: 217-227.

[4] A.C. Skeldon, G.Derks and D.-J. Derks (2016) "Modelling changes in sleep timing and duration across the lifespan: Changes in circadian rhythmicity or sleep homeostasis?", Sleep Med. Rev., 28: 96-107. weblink

[5] A.C. Skeldon, D-J. Dijk, G. Derks, (2014) "Mathematical models for sleep-wake dynamics: comparison of the two process model and a mutual inhibition neuronal model", PLOS ONE, 9, e0103877. weblink

[6] A.C. Skeldon, A.J.K. Phillips, D-J. Dijk, (2017) "The effects of self-selected light-dark cycles and social constraints on human sleep and circadian timing: a modeling approach", Sci. Rep., 7, 45158. weblink