Elements commonly form compounds to achieve stability, adhering to the octet rule, where atoms gain, lose, or share electrons to complete their outer electron shells. Compounds like NaCl arise from ionic bonds, where electrons are transferred between metals and nonmetals, resulting in charged ions. Stability is often not necessary for noble gases, which possess full outer energy levels and thus remain nonreactive.