As the character uses elemental spells, they will gain XP, which in turn will increase the level of those spells. In addition to this, the total value of the spell levels in each element combine to produce the level of Mastery in that element.
How to work out Mastery in terms of damage and resistance:
(Highest spell×0.3) + (2nd highest spell×0.35) + (3rd highest spell×0.05) + (4th highest spell×0.1) + (5th highest spell×0.2) = Mastery Resistance and Damage
Stasis, which is used exclusively by Foggernauts and some Monsters, follows a different rule when determining mastery. Stasis mastery is determined by the mastery of stasis spell like normal elements, but only half comes from the stasis spells themselves. The other half is from the overall mastery of the other 4 elements. Also Stasis mastery only affects stasis damage, it does give the fighter resistance to stasis damage.