One possibility is that this is because you&#x27;re working&#x2F;programming late at night, basically up until the time you&#x27;re going to bed (or within an hour or two of it).<p>I&#x27;ve found over the last 10 years that if I&#x27;m programming late (and really only programming, other types of work don&#x27;t do this to me), and don&#x27;t give myself 2-3 hours of down time before bed, my sleep is exactly as you described. My brain is running on work, it takes me a long time to fall asleep, and my night is spent drifting in and out of light sleep and work related thinking. It&#x27;s pretty bad and can screw me up for days and weeks at a time.<p>Usually this happens because my focus is very high with late night programming (to keep me going longer), and I don&#x27;t give my brain the time it needs to finish working through problems after I&#x27;m done coding. (You may be able to relate to thinking up a solution to a problem after closing your laptop, or waking up realizing there is a bug in your code. It&#x27;s this type of thinking that your brain needs to finish.)<p>I&#x27;d suggest that if you are programming late at night, stopping 2-3 hours before you usually go to bed and do some reading or watch a movie. A few nights of that is all that it takes for my sleep to get back to normal.