Ionic bonds are the bonds which are always formed between a metal and a non-metal.
Sodium atom has one electron in its outermost shell. Sodium is a metal. Every atom of an element wants to have 8 electrons in its outermost shell/orbits/energy levels excluding some elements like hydrogen and helium because they need 2. The atomic number of sodium is 11. Atomic number is the number of protons present in the nucleus of an atom. In every stable atom the number of electrons is equal to the number of protons.
Stable means that the atom has not formed an ion yet.
Therefore, the electronic configuration of sodium is :-
E.C:- K L M
2 8 1
To get 8 electrons in the outermost shell it can lose 1 electron.
Chlorine is a non- metal and it has atomic number 17.It is a stable atom therefore the number of electrons in chlorine atom is 17.
electronic configuration of chlorine is:-
E.C :- K L M
2 8 7
To complete its valence shell it would need 1 more electron and sodium wants to lose 1 electron so, one atom of sodium will give its one extra electron to chlorine. Because chlorine atom has more negative charge it will form a negative ion called anion and sodium will have more positive charge on it after losing 1 electron and will form a positive ion called cation .BEING OPPOSITELY CHARGED sodium and chlorine will attract each other and will give rise to an ionic bond and this bond will lead to the formation of an ionic compound called SODIUM CHLORIDE.
Remember , whenever you will write the name of an ionic compound always write the name of metal first followed by the non- metal.