Why does pain infliction sometimes make sex feel better?

I've always wanted to know why spanking and choking makes sex better, when outside of the bedroom, I wouldn't like those things done to me.