How can I write the formula for potassium nitride?
The correct answer is ##K_3N##.
To see how we arrived at that answer, we first have to examine the electronic configuration of ##K## and ##N##.
##K## has ##19## electrons and has the following electronic configuration ##rarr 1s^2 2s^2 2p^6 3s^2 3p^6 4s^1##
As potassium obeys the octet rule, it will lose one electron in its ##4s## subshell to achieve a stable octet noble gas configuration, forming the ion, ##K^+##.
Electronic configuration of ##K^+ rarr 1s^2 2s^2 2p^6 3s^2 3p^6##
##N## has seven electrons and has the following electronic configuration ##rarr1s^2 2s^2 2p^3##
Nitrogen also obeys the octet rule and will gain three electrons to achieve stable octet noble gas configuration, forming the negative nitride ion, ##N^-3##.
Electronic configuration of ##N^-3rarr1s^2 2s^2 2p^6##
Each nitrogen atom gains three electrons from three potassium atoms and each potassium atom loses one electron to a nitrogen atom. In this process each potassium atom becomes ##K^+## ion and each nitrogen atom ##N^-3## ion.
The first 1:30 of this video shows the movement of the electrons in potassium nitride (wordlessly).