It is actually something standardized more so than theoretical, however in terms of atoms in general the electrons are based on the amount of electronic shells that an atom has and the amount of electrons that atom can accommodate. In the case of sodium, it has three shells with 2 electrons on the first shell which is the maximum, 8 on the second shell which is also the max and 1 on their final shell
So simply put an ATOM of Sodium (Na) has 23 electrons because it has 23 protons which is a fact