Originally Posted by Arlyn
It is a vibration of their vocal cords.
They do it when they are happy and content, but they will also do it if they are distressed or in pain.
It is thought that they purr when distressed as a means of reassuring themselves.
I agree with that! We chose our cat based on the fact that she was the only one to purr when we picked her up. Turns out she was just terrified!
I've accidentally frightened her before (snuck up on her... hard to do!) and after her initial yelp, she started purring.
Of course, she purrs when she's happy too. The happy purr is usually accompanied by the front paw kneeding motion.