All the electrons in 1 atom are characterized by a series of 4 numbers, known as quantum numbers. These numbers (n, l, ml, ms) describe the state of each electron (in which level, sublevel, orbital it is and its spin). For 2 electrons to coexist in the same atom they must differ in at least of these numbers. If they occupy the same level, sublevel and orbital, then they must have different (and opposite) spins. This is known as Pauli exclusion principle.
Also, to gain stability atoms can gain, lose or share electrons. In doing so they form bonds. There are 3 kinds of bonds:
Ionic bonding: these are formed between metals and nonmetals. Metals tend to lose electrons and form cations (positive ions) and nonmetals tend to gain electrons and form anions (negative ions). Cations and anions attract each other due to <em>electrostatic forces</em> between <em>oppositely charged ions</em>.
Covalent bonding: these are formed between nonmetals, which share pairs of electrons so as to reach the <em>electron configuration</em> of the closest noble gas (the most stable electron configuration).
Metallic bonding:valence electrons are loose in metals, so they move together as a "sea of electrons", acting as <em>"glue"</em>of the remaining positive <em>cores</em> (electrons that are negative charges serve to attract the positive charges of the cores).
An is formed when an atom loses or gains one or more electrons. Because the number of electrons in an ion is different from the number of protons, an ion does have an overall electric charge.