Anesthesia works by altering the activity of the brain, leading to a temporary loss of consciousness. This allows patients to undergo surgery without experiencing pain or distress. However, the exact mechanisms by which anesthesia affects consciousness are still not fully understood.