Sodium is in the first group of the periodic table and has an atomic number of 11. That means it has 11 protons and 11 electrons.
The electrons are arranged in energy levels around the nucleus. The first energy level contains 2 electrons, the second energy level contains 8 electrons, and there is a single electron in the third energy level.
When sodium reacts with other elements to form compounds it loses the one single electron in the third energy level. That leaves it with 10 electrons,2 in the first level and 8 in the second. Thus, the second energy level now has its full 8 electrons, fulfilling the octet rule.