Octet law states that every atom tries to attain a octet valence shell (8 electrons in their valence shell) to attain a more stable state. For attaining this they form bonds(covalent,ionic etc) with other atoms. Please ask if you any more doubt on this, I'll try to help