I never did understand it, until recently. I've never been the type to need to harm myself, no matter how depressed I got. I'm a Masochist though and emotional pain is worse but thats another story.
However, I do know
some people do it to stop feeling like shit and to forget emotional pain or something similar.
Most people do it / say they do it, cos of some attention deficit problem.