The rule of thumb is to invest in the most prominent stat of the Pokemon, unless circumstances say otherwise (ie mixed sets). It all boils down into what you want your Pokemon to achieve. Generally you'd want your attackers to have max EVs in attack/special attack and speed, whilst defensive Pokemon have max HP and max defense/special defense. Never invest in every stat because you think it's better: it's actually not.
There are special cases, like when you want to achieve a certain KO or outspeed a certain 'mon.
This Smogon article helps immensely when you're not very familiar with EVs and EV training. Though the name implies 4th gen, the practice still applies since there hasn't been any changes with how EVs and stats are handled anyway.