It depends on what atoms comprises the molecule. If you look on the periodic table, the columns give us insight into how many bonds the particular atom likes to have to be stable (happy).
Lets say you have a water molecule, The O likes to have two bonds since it has 6 valence electrons and wants to have 8. It will share two of its electrons with another to have a total of 8 in its outer shell. These two electrons come from H which unsurprisingly has only 1 electron in its outer shell and prefers to have one bond.
The column with carbon needs four bonds; Nitrogen, three; Oxygen, Two and Fluorine,1. Bonding with metals and metalloids is slightly complicated due to the structure of these atoms.
OR I'll tell you a simple way to do it, remember the following is for hydrocarbons only.
1. If the number of hydrogen atoms is 2 more than double the number of carbon atoms then it will be an alkane(single Bond)
2. If the number of hydrogen atoms is exactly equal to double the number of carbon atoms then it will be an alkene(double Bond)
3. If the number of hydrogen atoms is 2 less than double the number of carbon atoms then it will be an alkyne(triple Bond)