# How do I find out the number of bonds an atom must link to?

I've always been told that carbon bonds with four hydrogens and that nitrogen bonds with three hydrogens, like in benzene and hexazine, respectively.

What's the name of this type of bonding and how does one come up with the number?

As an example consider $\ce{N}$ that has five electrons in its outer shell, and $\ce{H}$ that has just one. $\ce{N}$ wants three more electrons and can get them from covalent bond with hydrogen. $\ce{H}$ want one more electron (this is an exception) in its outer shell to fill it up, so will kindly receive them from nitrogen.
Atoms, especially those in the first 2 or 3 rows of the Periodic Table, try to attain a filled outer shell of electrons. This gives them an inert gas electron configuration and a special stability. They can achieve this filled outer shell of electrons in one of two ways, they can donate or accept electrons (ionic bonding) or share electrons (covalent bonding). An example of ionic bonding would be sodium with an electronic configuration of $\ce{1s^2 2s^2 2p^6 3s^1}$. By donating (losing) one electron it attains the inert gas electronic configuration of neon ($\ce{1s^2 2s^2 2p^6}$). On the other hand, atoms like carbon ($\ce{1s^2 2s^2 2p^2}$) and nitrogen ($\ce{1s^2 2s^2 2p^3}$) would have to gain or lose too many electrons to achieve an inert gas configuration, so they typically form covalent bonds by sharing electrons. In order for carbon to achieve the neon configuration it would need to share 4 more electrons. That is why carbon typically forms 4 covalent bonds. In the case of methane, $\ce{CH4}$, each hydrogen atom brings one electron to share with the carbon atom and in turn each hydrogen shares one electron from carbon. By sharing electrons like this, each hydrogen achieves a stable helium configuration and carbon achieves a stable neon electron configuration. In the case of nitrogen, it only needs to share 3 more electrons in order to achieve the neon configuration. It can do this by forming 3 covalent bonds. If we look at ammonia, $\ce{NH3}$, we can apply the same reasoning we applied to methane. By sharing electrons with 3 hydrogen atoms, both the nitrogen and hydrogen atoms can achieve inert gas electronic configurations. Simply stated, atoms try to form as many bonds as necessary, be they ionic or covalent, in order to achieve an inert gas configuration. While there are many exceptions to this approach, especially for heavier atoms, it does seem to work reasonably well for the lighter elements.