IVs, or individual values, are set values given to a Pokemon at creation. They range from 0 to 31. The way IVs work is that they add however many IVs there in a specific stat to the stat at level 100. An example like this could be a level 100 Bulbasaur with an HP IV of 0, which would be a stat total of 200 if it had no EVs in it (which I'll explain later). If said Bulbasaur had an HP IV of 31, the HP stat would be equal to 231 (again, with no EVs).
EVs, or effort values, are values that can be changed over time when you're training a Pokemon. When you defeat a Pokemon, any Pokemon in your party that receives EXP from you fainting your opponent receives an EV yield. EV yields depend on the Pokemon. Some Pokemon give more EVs, but all Pokemon all give EVs for one certain stat. So lets say you had a bulbasaur again and you defeated it. All Pokemon that got EXP would receive an EV yield of 1 for the special attack stat. This number can modified through use of items, such as the power items, macho brace, and pokerus.
Here's a few basic rules on EVs, however:
- One stat cannot hold more than 252 EVs (a stat gain of approximately 63, but not always).
- 4 EVs, at level 100, will boost a stat by one or two points (usually one, however). If your Pokemon is not level 100, it would take more EVs to increase a stat. In the case of your level 8 ralts with 40 special attack EVs, it would have a special attack stat of 13-15 depending on IVs.
- A Pokemon cannot have over 510 EVs total. Yes, that means 2 of the EVs are going to be useless at level 100.
Natures are also things that will affect stats. You can find a list of natures here. If the stat has a + next to it, it multiplied the corresponding stat by 1.1, and the other stat (-) by 0.9. Natures do not affect HP stats.
If you want the full, more complicated stat equation, you'll find it here. I just explained it here though to make it easier. If you don't feel like using a calculator to figure it out, this site will do it for you.
More info on EV training. Smogon might be able to explain it better than I can.