there are so many reasons for this i dont even know where to start. Personally, I began by putting the occasional cigarette out on my arm, progressing to some pretty serious hot-iron branding and ending in nights where I would simply beat the shit out of myself fight club style. Initially, i used it as a kind of punishment. If I had messed up or done something wrong or was mad at myself in general, i gave myself a little "slap on the wrist." Later, it became a method of personifying emotions that i didn't know how to deal with. I was trying to take the inner pain and turn it into something physical that my body could heal. A comedian named Lewis Black does a little bit on this topic ("Because if I'm going to hurt that bad, I'm going to be the one to do it to myself. Oprah calls that empowerment"). The self-beatings came after a string of failures. I still don't quite understand where they came from, but therapists like to blame my parents for creating a self-disciplining mechanism in me that was simply out of control ( I was raised in a strict roman catholic household, and was spanked as a child). True masochists derive sexual pleasure from pain. This has to do with the fact that when the body senses pain, it immediately releases pain killers that provide a sort of high; thus generating the phrase, "pleasure from pain." If you're doing this to yourself, stop it. Either you don't have the emotional strength to deal with your life, or you're just looking for a cheap way to push the happy button. It's not going to help, it will only make things worse. Nobody will help you if you don't help yourself.
I would go so far as to say that humans will not do something that they think is bad for them. The percieved reward (like the cash in a bank robbery) is what drives people to do this. They believe, for one reason or another, that what they are doing is beneficial to them.