Objects become electrically charged by gaining or losing electrons, so that they have unequal numbers of protons and electrons. Gaining excess electrons causes a negative charge, while losing electrons causes a positive charge. A charged object behaves differently than an object with neutral charge, attracting objects with an opposite charge and repelling objects with a similar charge.
There are many processes that cause an object to become electrically charged. Charge occurs in discreet units, with each positive or negative charge being equal to some multiple of the charge of individual protons or electrons. Individual charged particles are known as ions. These occur in table salt, for instance, which is a crystalline lattice of sodium and chloride ions, held together by their opposite charges. Despite being composed of charged particles, salt itself has little charge, since the positive and negative charges in it are nearly equal.
Mechanical processes, such as rubbing a balloon on hair, also cause electrical charges. Different elements have different electron affinities. When a substance with a greater electron affinity rubs against one with a lesser affinity, it steals some of the electrons, causing both to gain a charge.
Excess charge can be dangerous. Lightning, for instance, occurs due to a charge difference between the atmosphere and the ground. This difference in charge builds until it exceeds the electrical resistance of the air, and then a stream of electrons travels between the air and the ground, equalizing the charges.