Gap is the difference between your level and you HIGHEST mastery...meaning that if you are lvl 16 and have all masteries at lvl 3, you'd have a 13 gap...but if you upgraded anything to lvl 15, you'd only have a gap 1.
Gap determines how much XP and SXP you get...if you'd have 0 gap you would get much more XP and less SXP....o the other hand, if you have a 9(or higher, coz after gap9 the ammount remains the same, even for example at gap25) you'd get a ton of SXP and little XP....and levelling would become hard...but at least you have skill points

. That's the basis of SP farming.