Those are called Effort Values, commonly called EVs, and they are a result of EV training. EV training became much easier with Gen 6 in a mode called Super Training. In Gen 5 you could take your Pokemon to Join Avenues for some easy EV training.
Every Pokemon, whether wild or a trainer's Pokemon, has an EV yield. What they yield depends on the Pokemon itself. For example: All Sevipers give off 1 Attack EV and 1 Special Attack EV.
You need 4 EVs to increase a stat by one point. The maximum amount of EVs you can get in one stat is 255, but people only go to 252 because that is the highest number divisible by 4. The total number of EVs one Pokemon can have is 510 EVs.
Here are some helpful guides on EV training.
How to EV train correctly
How do you EV train
A more detailed look and explanation of EVs