It's the nerves in our entire body that responds and feels the pain or generates the pain. If the anesthesia is local, then the nerves in a particular portion of your body is blocked and there won't be any pain or sensation in that area. So, the doctors are able to perform a surgery or a procedure in that particular localized area. For more in depth surgeries, doctors prefer general anesthesia. This causes the patient to be completely unaware of their surroundings and they go into a deep sleep. The nerves in their body also become unresponsive, and they don't feel any pain during the procedures.
The anesthesia procedure is accomplished through several means administered into the body. This is through gasses that the person inhales through a tube, some administer drugs through machines that measure the amount necessary to keep the patient unconscious enough for the surgery and then quickly enable them to come back into consciousness. There is also IV and other intravenous methods of internal medications.