The octet rule refers to the idea that most atoms want to have 8 electrons in their outer energy level/valence shell. An exception to this rule would be hydrogen. It wants to have only 2 electrons in its valence shell. This is known as the duet rule.
The octet rule is a broad general principle that atoms from main-group elements will tend to combine such that there are eight atoms in their valence shell. This is the same electron configuration that the inert (meaning that they rarely react) noble gases have.
Main-group elements all elements except for Hydrogen, in groups 1 and 2 and 13-18 in the periodic table.
The number of valence electrons can be counted using a Lewis electron dot diagram. Covalently shared electrons are counted twice, once for each element, and ionic bonds transfer an electron from one element to the other such that each element in the compound follows the octet rule.