I recently found out that programming late at night causes sleeping problems, so what are the best hours for 'after-job' programming? Maybe there is some time interval that should be set after finishing programming and going to bed, or some activity involved?

  • 8
    How did you discover this? Maybe some stay up at night programming because they already have a sleeping problem.
    – JeffO
    Aug 11, 2011 at 13:28

8 Answers 8


so what are the best hours for 'after-job' programming?

I think the best time is in the early morning, at the day break, right after waking up and when your mind is fresh... It doesn't cause any sleeping problems either; it encourages sleeping early... Remember:

Early to bed, early to rise, makes man healthy, wealthy and wise...
  • 4
    it`s more than proverbial, not sleeping enough = high Blood Pressure = serious health issues : usmansheikh.com/random/a-lack-of-sleep-can-kill-you
    – Matthieu
    Aug 11, 2011 at 12:58
  • 6
    Totally agree on this. I have three kids and after hours coding is pretty much never going to happen and if through some miracle it does.. I'm super tired by the time everything has wound down and they're in bed I'm not thinking clearly and the code suffers. However -- in the morning (say 5 am) it's a totally different story. The kids are asleep, the coffee's good, and the code just writes itself.
    – unclejamil
    Aug 11, 2011 at 13:21
  • 1
    So true on everything said. I have found out recently (for most of my life i have stayed up late and struggled all day) that you can't control when you fall asleep only when you wake up. Force yourself to get up at a specific time (5am for me) every day and after about a week your body will handle the rest. Stay on the schedule for a while and even when you "need" to stay up late your still going to get up early so your schedule doesn't get trashed.
    – Ominus
    Aug 11, 2011 at 15:11

Listen to your body. It knows when you should take rest and when you should be coding.


For me, right before dinner.

Hunger provides pressure and helps me code faster and more efficiently (think of it as a project milestone deadline). It also forces me to stop well before midnight so that it doesn't negatively impact my health.


I tend to find that programming late will keep me from sleeping. Anything that I find stimulating will tend to prevent my mind from winding down, I'll be laying in bed visualizing what I want to do with code or figuring out how things will work.

I also find that if I push myself too long, my code needs revision the next morning.

I find I need to put things down at least an hour before I intend to head to bed. I tend to watch reruns (M*A*S*H in particular) that I've seen a million times and won't try to stay up to finish :)

That's me... hope you figure out what works for you.


Many years ago I was coding something and checked the watch. It was around 7pm and I thought "ok, two more lines and then eat dinner". After those two lines (?) it was 2am...

Every now and then I find myself sleeping and thinking about code, what to do with, how to fix a bug or wake up in the morning and having/making plans for coding later on.

IMHO, it's all related to how much you identify yourself - not literally - with your profession/hobby and how much you like it. If the above happens it means that you are doing something that you like. You don't need to force yourself to think about coding. It comes naturally. In general that's a good thing.

To keep this in non-excessive limits I made some rules for myself:

  • in the office I have an Outlook-alarm set up telling me when to go home

  • at home I don't have an alarm, but whenever the time roughly is in a timeframe where I usually eat, I stop and eat.

  • to cool off before bed I either watch TV, play some game, read something, ... Basically I do something that makes my brain think of something else. I usually end up being tired.

You can also try to set up a daily routine that you do before going to bed to draw your brain's attention away from the code, like writing mails, reading newspapers, doing the dishes, separating laundry, going for a walk, go to supermarket (if it is open that late), call or talk to somebody, ...

The time you need really depends on yourself. For some it takes a few minutes, some need an hour or more.

In other words it's important to get your sleeping pattern right. If you can't come up with one, don't code for a week or two and set your focus onto something else.

THEN - and only then - you can think about your productive hours. Why? Because then you have slept properly and wake up fresh in the morning. Otherwise you end up with relaxing from your more or less bad sleep and thus run into another daily time pattern of your organism.

Usually your body tells you what's good and what's bad. If it conflicts with other people's habits, well, it's nobody's fault, it's just the way it is. We are all different after all :).

Early bird vs. night owl. There's no right or wrong on this question. What works for others doesn't necessarily work for you. So whatever you read here can only be suggestions.


Any activity that promotes relaxation can be used to bridge from working to ready to sleep mode. I usually watch some TV, but whatever floats your boat.


I'm still somewhat struggling with this issue myself, but here are some of my findings:

  • Late-night coding is not the cause, it's a symptom

Some possible causes (YMMV):

  1. Caffeine
  2. Irregular times of meals

For me, lowering caffeine intake helped with sleeping when I planned, and eating regularly helped with waking up when I want (this later one had especially dramatic effect on me).

I also experienced a "critical point" in exhaustion, meaning that if I stay up too late, my body will prevent me from sleeping for 2-3 additional hours.

  • The last point is exactly what I'm experiencing.
    – user1449
    Aug 11, 2011 at 12:44

The light from computer screens is typically very good at keeping you awake. For this reason, you should have a gap between computer use (of any kind) and trying to sleep, and you should be wary of staying up past your bedtime to "just do a little bit more". Otherwise, you may end up lying awake at night, unable to drop off. The duration should be reached by experimentation, as everyone is different, and the kinds of computer usage vary.

You may find some success using f.lux to allow you to keep coding right up until bedtime.