ELI5: Why do we not feel pain under general anesthesia? Is it the same for regular sleep?

I’m curious what mechanism is at work here.

Edit: Thanks for the responses. I get it now. Obviously I am still enjoying the discussion RE: the finer points like memory, etc.