Well, that is simple.

A Carbon (C) makes 4 bonds, a Hydrogen (H) or a halogen (X) makes 1 bond and Nitrogen (N) makes three bonds. So in a molecule with $c$ Carbons, $h$ Hydrogens, $x$ halogens and $n$ Nitrogens, we will have $4c+h+x+3n$ "*bonding capacity*".  

Assuming there are no rings, no double/triple bonds, we must have $c+h+x+n-1$ bonds in between these atoms [think like how many dashes you can draw between $m$ $\ce{O}$'s: $\ce{O-O-O}$ two dashes for three $\ce{O}$'s apparently].

Since each bond uses one "bonding capacity" from each of the two atoms its binding, $c+h+x+n-1$ bonds are using $2(c+h+x+n-1)$ bonding capacity. So the remaining capacity is:

$$(4c+h+x+3n)-2(c+h+x+n-1)=2c-h-x+n+2$$

If this is larger than zero, it means our molecule is unsaturated, i.e. still has a capacity to make bonds. And our assumption that "there are no rings, no double/triple bonds" is wrong. This bonding capacity is used in forming new bonds either in rings or in pi-bonds.  Since each bond uses two capacity one from each side we should have $c-h/2-x/2+n/2+1$ "unsaturated" bonds.