Awareness during surgery is a rare phenomenon, but is nonetheless a cause for some concern. It was even the subject of a movie thriller starring Jessica Alba called Awake". Therefore, not surprisingly, it is a common fear of people going under for the first time.
First, it is important to understand that, with the exception of general anesthesia, complete unconsciousness is usually not the goal of surgical anesthesia. In fact, one of the reasons for choosing another type of anesthesia is that the patients awareness can be helpful to the surgeon during the procedure, as well as providing some measure of protection to the patient.
With local or regional anesthetic, you remain totally conscious, although sometimes oral sedatives are given to help you relax and feel comfortable. With intravenous conscious sedation, although the patient is not technically unconscious, one of the goals is often to minimize or eliminate memory of a procedure. However, memory loss isnt always complete. Having some memory, especially of the beginning or end of a procedure, is not all that unusual, and shouldnt be of much concern.
When it comes to general anesthesia, awareness during surgery is rare. Usually, this phenomenon occurs when anesthesia dosage must be decreased due to complications such as significant blood loss, respiratory distress, or heart failure.
The good news is that even in those cases of awareness during anesthesia, the experience is almost never painful. If you do experience awareness during general anesthesia, be sure to speak up about it to your surgical team.
Sources:
Anesthesia: A Look at Local, Regional and General Anesthesia; Consumer Information Sheet; Mayo Clinic; http://www.mayoclinic.com/health/anesthesia/SC00026 Interview with Adam Tattelbaum, MD conducted on 12-17-07.

