A stable complex (with electron configuration of the next highest noble gas) is obtained when the sum of the metal d-electrons, electron donated from the ligand, and the overall charge of the complex equals 18.
(from http://easyweb.easynet.co.uk/~miky/projtpag/pag3.htm)
The 18 electron rule (also known as the Effective Atomic Number Rule or EAN rule) was originally proposed by N.V. Sigwick when extending the octet rule proposed by G.N. Lewis in applying it to organometallic compounds. The idea behind both of these rules is that in a compound the sum total of all of the electrons would have the configuration of a noble gas.

With the octet rule there is the basic assumption that the central atom in the compound is 8 (the maximum capacity of the s and p orbitals). The 18 electron rule is based on a similar idea as the octet rule, however it takes into consideration the d orbital too - 2 (s) + 6 (p) + 10 (d) = 18.

There are two ways to count electrons (example of Fe(C5H5)2):

Ionic counting

With this form of counting, the metal is considered alone and that the ligands bonding to the metal are either anionic or cationic. The metal is then modified to the proper oxidation state.

C5H5- provides 6 e-, Fe2+ provides 6 e- and another C5H5- provides 6 e- sums up to a total of 18 electrons.

Covalent counting

With covalent counting, the ligands are considered to be neutral and that the metal at the center is zerovalent.

C5H5 provides 5 e-, Fe0 provides 8 e- and the second C5H5 provides 5 more e- for a total of 18 electrons.

When looking at counting the structures it is important to realize that different structures will have different bond counts for covalent counting and ionic counting. The electron count of metals can be seen by looking at the ground state - Iron (Fe) is [Ar]3d64s2 thus, 6 + 2 is 8. The other way to count the number of electrons is to look at the periodic table and count groups:
``` 19 20    21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36
K Ca    Sc  Ti   V  Cr  Mn  Fe  Co  Ni  Cu  Zn  Ga  Ge  As  Se  Br  Kr

1  2     3   4   5   6   7   8   .   .   .   .   .   .   .   .   .   .
```
8 steps to Iron (Fe) thus 8 valance electrons.

If there are less than 18 electrons in the outer shell, the atom will have to either dimerise or accept an electron to for a stable structure. Dimerization is the process where two unstable molecules join together to form a stable structure. This can be seen with manganese (Mn) where Mn(CO)5 is not stable, however, Mn2(CO)10 is - essentially providing a mirror of the original structure with the two Mn atoms joined by a bond. The other possibility is to accept an atom from an ion such as sodium (Na). Na+[Mn(CO)5]- is stable.

This is not a hard and fast rule and many exceptions abound. For the 18 electron rule to work, there must be 18 electrons for bonding - not the case with metals at the ends of transition series such as Sc, Ti, Ni, and Cu. When the element is likely to form square planar complexes (such as nickel), this often results in a 16 electron structure. Steric (spatial) limitations with some elements will prevent them from having 18 electrons in the outer shell available for bonding - this is the case with vanadium which can form V(CO)6 (Hexacarbonylvanadium) which has 5e- with vanadium and CO (2e- x 6) for a total of 17 electrons. Vanadium too small of an atom to dimerise or accept an electron from an ion.

http://science.ntu.ac.uk/projects/Organometallics/James/topics/intro/intro.htm
http://www.chem.ualberta.ca/~chem33x/chandouts/lecture16_files/lecture16.ppt
http://www.chem.wm.edu/courses/chem402/orb18e.html
http://www.ilpi.com/organomet/electroncount.html
http://easyweb.easynet.co.uk/~miky/projtpag/pag3.htm