atoms 'like' to have 8 valence electrones. sodium has one electron 'in excess' and chlorine 'lacks' in one. so they just exchange :) both are happy. then the ionic bond is formed because chlorine is now charged negative (additional electron) and sodium is charged positive (gave up one electrone) - the opposite charges cause electrostatic pull. many atoms, many bonds and thats how salt is built.