Most people would understand what is meant by saying one is "in the zone."  The psychological concept goes by "flow."  Quoting from Wikipedia,

Flow is the mental state of operation in which a person performing an activity is fully immersed in a feeling of energized focus, full involvement, and enjoyment in the process of the activity. In essence, flow is characterized by complete absorption in what one does.

Mihály Csíkszentmihályi (yah, I have no idea how to pronounce that) wrote a book about flow and describes 6 required factors to achieve flow (borrowed from Wikipedia):

  1. Intense and focused concentration on the present moment
  2. Merging of action and awareness
  3. A loss of reflective self-consciousness
  4. A sense of personal control or agency over the situation or activity
  5. A distortion of temporal experience
  6. Experience of the activity as intrinsically rewarding

I think programming is uniquely suited to the creation of a state of flow.  When working on a programming problem I inherently become more intensely focused as more and more context is pulled in to my working memory.  All the bits and pieces have to be tracked and accounted for.  The more complex the problem the less room there is for extraneous thoughts.

This all-encompassing aspect of working memory feeds into point 2.  I'm not so much typing at a keyboard as I'm modifying the interconnected pieces of the software as they're held in my working memory.  The typing is more a way to capture the changes as I produce them in my head.  But I'm not thinking about the keyboard in any way, it may as well not exist.

As the construction of the software takes over my mental processes I'm forced into letting go a sense of self-consciousness.  There isn't any room in memory or processing power left to worry about it.  It is during these times that others might interrupt me to inform me that I'm whistling or tapping on my desk or some other thing that's bothering them.  I become completely unaware that I'm doing it.  Having a private office at work really helps in this regard.  When I must maintain self-conscious awareness to be courteous to those around me it inhibits the ability to enter a state of flow.

Programming is entirely about personal control over the situation.  It is the programmer's mind being melded with the limitations of the machine and language.  Once the keyboard and the monitor melt away as mere extensions of one's own thoughts and senses it is simply a matter of solving the problems and verifying the solutions.

The time distortion is one of the most fascinating aspects of flow.  While in flow I can work for hours on something and it will feel like just minutes.  Hunger disappears, emails are ignored, music is unheard.  What I've recently been able to observe is the "awakening" process that occurs at the end of flow.

A few weeks ago I was working on a new feature in one of our applications at work.  I had my browser up to test changes as I went, energetic music was playing, my text editor was opened up with all the needed files loaded.  I loaded all the relevant information into my head and began implementing the solution.

As my commits to version control piled up and the task was completed I was aware of the state of flow ending.  It's very much a let down.  Flow is a heightened state of awareness and efficacy.  Coming out of it feels something like rapidly becoming dumber.

As I came out I became aware of the music playing to the point that it became distracting and turned it off.  I glanced at my email inbox and wondered how that many emails had come in without me noticing.  I noticed the time and realized that it was both after time to head home and that I was really hungry.  And, ultimately, I re-entered reality with almost an awed feeling of having lived in a land where thoughts and actions blurred.  Where my abilities were a cut above the normal day-to-day levels.

Achieving flow is not something that happens daily for me.  It can be weeks between sessions.  But when I can achieve flow it reminds me how enjoyable problem solving can be.  Writing software is the medium, but not the goal.  I believe it's the satisfaction of finding and implementing solutions that drives flow for me.