The octet rule is a general rule of thumb in chemistry. It predicts that elements will combine in such a way that they have 8 electrons in their outermost shell; once they attain this stable state, they are said to have a full octet. As with all other rules of thumb, there are many exceptions, so you shouldn't try to apply it blindly to all elements. For period 2 elements (carbon, nitrogen, oxygen, etc), however, it's a very useful tool to help you draw molecular structures.
Pick one of the main-group period 2 elements after boron (carbon, nitrogen, oxygen, fluorine) or one of the period 3 elements like sodium, magnesium, sulfur, phosphorus or chlorine. Count how many columns the element is from the right side of the table; this is the number of electrons it has in its outermost shell. Sodium, for example, has one electron in its outermost shell; oxygen has six, fluorine has seven, chlorine has seven, and so on.
Determine whether the element is in the first two columns of the table (e.g., sodium, magnesium, etc.). These elements tend to lose electrons so they can attain a full octet. In other words, they become ionized. Once they have done so, their outermost shell has 8 electrons. If the element is not in the first two columns, proceed to the next step.
Determine how many electrons the atom would need to gain in order to have a full octet. This number is equal to the number of bonds it will typically form. Oxygen, for example, needs two more electrons and typically forms two bonds, while carbon needs four more electrons and typically forms four bonds. This is not always true, of course; nitrogen needs three more electrons and typically forms three bonds, but nitrogen with four bonds is quite possible (although a nitrogen atom with four bonds will have a positive charge). This arrangement of nitrogen with four bonds satisfies the octet rule, however, because nitrogen with four bonds has 8 electrons in its outermost shell.
Check any chemical structures you draw using the octet rule. Look at each atom in the structure and count up the number of bonds it's formed, then multiply by 2. Add the number of electrons in "lone pairs" (electrons that do not participate in bonding). The total number of electrons in lone pairs and bonds around any atom in the structure should equal eight to satisfy the octet rule.
There are many exceptions to the octet rule. It doesn't apply for transition metals, and elements in period 3 and below can have more than 8 electrons in their valence shell. Phosphorus, for example, can form a compound called phosphorus pentachloride, in which it has formed 5 bonds -- which would otherwise be a violation of the octet rule. You'll learn more about these kinds of exceptions and the principles that explain them as you make progress in chemistry.