You determine the valence electrons by using the Periodic Table.
Let's assume you're using a table that has the groups numbered 1-18.
The electron configurations of ions are those of the neutral atoms plus or minus a number of electrons equal to the charge on the ion.
Groups 15 to 17
Write the electronic structure for the neutral atom. Then add electrons to get a total of eight.
E.g., for #"Cl"^-#, we get
#"Cl": 1s^2 color(white)(l)2s^2 2p^6color(white)(l) 3s^2 3p^5# but #"Cl"^-# has one more electron.
∴ #"Cl"^"-": 1s^2 color(white)(l)2s^2 2p^6 color(white)(l)3s^2 3p^6#
Groups 1, 2, and 13
Write the electronic structure for the neutral atom. Then remove the outermost electrons.
For #"Na"^+#:
#"Na": 1s^2 color(white)(l)2s^2 2p^6 color(white)(l)3s#, but #"Na"^+# has one less electron
∴ #"Na"^+: 1s^2 color(white)(l)2s^2 2p^6#
Groups 3 to 12
Remove #s# electrons before #d# electrons.
E.g., for #"Cr"^"3+"#
#"Cr": 1s^2 color(white)(l)2s^2 2p^6 color(white)(l)3s^2 3p^6 color(white)(l)4s 3d^5#
∴ #"Cr"^"3+": 1s^2 color(white)(l)2s^2 2p^6 color(white)(l)3s^2 3p^6 color(white)(l)3d^3#
You remove the #4s# electron first, followed by two of the #3d# electrons.
EXAMPLES
Write the electron configurations for #"O"^"2-"#, #"Ca"^"2+"#, and #"Zn"^"2+"#.
Solutions
#"O": 1s^2 color(white)(l)2s^2 2p^4#
#"O"^"2-": 1s^2 color(white)(l)2s^2 2p^6#
#"Ca": 1s^2 color(white)(l)2s^2 2p^6 color(white)(l)3s^2 3p^6 color(white)(l)4s^2#
#"Ca"^"2+": 1s^2color(white)(l) 2s^2 2p^6 color(white)(l)3s^2 3p^6#
#"Zn": 1s^2 color(white)(l)2s^2 2p^6 color(white)(l)3s^2 3p^6 color(white)(l)4s^2 3d^10#
#"Zn"^"2+": 1s^2 color(white)(l)2s^2 2p^6 color(white)(l)3s^2 3p^6 color(white)(l)3d^10#