The electronic configuration of sodium is 2, 8, 1 and the electronic configuration of chlorine is 2, 8, 7.
In pursuit of stability sodium atom loses its one electron to chlorine and the chlorine atom gains it which causes the formation of the sodium chloride compound.
Since sodium chloride is formed by the transfer of electrons between the elements, therefore, it is an ionic compound.