The total number of cations (positive ions) should be equal to the total number of anions (negative ions), so that the overall electrical charge is neutral.
The cations calcium (Ca2+) and magnesium (Mg2+) are also commonly measured, but they aren't used to calculate the anion gap.