Degree of ionization and Saha equation Say you want to calculate degree of ionization for different gases in atmosphere of a star with abundances similar to those in Sun (let's assume you only have hydrogen, helium and sodium) over the temperature range (from 2000 K to 45000 K for example) using Saha equation: 
$$\frac{n_{i+1}}{n_i}=\frac{g_{i+1}}{g_i} \frac{2}{n_e} \frac{{(2\pi m_e)}^{3/2}}{h^3} {(k_B T)^{3/2}} e^{-\chi /k_B T}$$,
which you write down for all three elements and of course next to abundances and temperature you also know ionization potentials $\chi$ for each element.
How can one calculate electron density in that case and how does it change? I understand, that at lower temperatures number of electrons is equal to number of ionized sodium atoms since it is the easiest to ionize (and in general $n_e=n_H^1+n_{He}^1+n_{Mg}^1$, where 1 means first level of ionization) but that doesn't help much. And additional question: should higher levels of ionization be included, given the temperature? 
 A: If you are dealing with elements heavier than helium ('metals' in astrophysical jargon), then for 45000 K you may need to consider higher ionization states. Indeed, this temperature corresponds to a thermal energy of $k_B T\approx4~$eV, and for magnesium, the 2nd ionization potential is 15$~$eV. If your accuracy requirement is of order $2\times\exp(-15/4)\approx ~$5%, then you need to include neutral, singly ionized and doubly ionized ions. For greater accuracy, include more ionization states. You can find ionization levels for all ions of all elements at the NIST web site.
However many ionization levels you include, you can calculate electron density as
$n_e=\displaystyle\sum_{Z}\sum_{i=1}^{Z}i\cdot n_i(Z)\qquad\qquad$(1)
Here $Z$ denotes the chemical element ($Z=1$ for H, $Z=12$ for Mg, etc.) and $i$ denotes the ionization level. $n_i(Z)$ is the number density of $i$ times ionized element Z. E.g., $n_0(12)$ is the density of Mg atoms, $n_1(12)$ is the density of singly ionized Mg, $n_2(12)$ is the density of doubly ionized Mg, etc. These densities come from the Saha equations and the condition 
$\displaystyle\sum_{i=0}^{Z}n_i(Z)=n(Z),\qquad\qquad$(2)
where $n(Z)$ is the number density of nuclei of element $Z$ (or the density of $Z$ atoms at low temperature).
In case you are wondering why under the $\sum$ sign, densities $n_i$ are multiplied by $i$, here is an explanation. Every singly ionized ion contributes $i=1$ electron to the plasma, every doubly ionized ion contributes $i=2$ electrons, etc.
