How do scientist obtain the value of enthalpy of formation?
There is a consent to start with: the standard enthalpies of formation of elements (like $\ce{H2}$), at standard conditions ($\pu{1 bar}$, $\pu{298.15 K}$) are set to zero.  If there are several forms of one element, than the most stable polymorph is chosen as reference (except for phosphor, ref).

More generally, to determine the $\Delta{}_fH^\circ{}$ of other compounds, you may embark experiments by calorimetry. By means of a calorimeter, you are able to record the energetic changes that occur in the course of a reaction.  For example for the exhaustive combustion of carbon with oxygen:

$$\ce{C + O2 -&gt; CO2}$$

all the heat recorded is due to the formation of carbon dioxide. Since this reaction equation was balanced that it equals only one mol of product ($\ce{CO2}$), the more general standard reaction enthalpy ($\Delta_{\text{R}}H^\circ{}$)  equals to the standard enthalpy of formation ($\Delta_fH^\circ{}$).  And by one experiment, after an other, the body of experimentally determined enthalpies grows.

Based on other experiments than combustion, one was able to determine how much energy is necessary to break a bond between atoms which is called bond dissociation energy. Conversely, this value expresses how much energy over all is released if two atoms establish a bond with each other.  In some instances, these energies are (comparatively) small, for example single bonded $\ce{Cl-Cl}$ ($\pu{242 kJ/mol}$), in other instances (comparatively) large, like triple bonded $\ce{N#N}$ ($\pu{945 kJ/mol}$).

If one knows the structure of a compound, which atoms are connected with each other and how (single, double, triple bond), than these bond dissociation energies may be used to estimate the standard enthalpy of formation of the new compound, for example by an increment system. Alternatively, by virtually setting up for example a combustion reaction of exactly one mole of the new compound into $x$ moles of $\ce{H2O}$ and $y$ moles of $\ce{CO2}$.  Then, the calculation to perform is 

$$\Delta_{\text{R}}H^\circ{} = \sum_{\text{all products}}{\Delta_fH^\circ{}} - \sum_{\text{all starting materials}}{\Delta_fH^\circ{}}$$

where $\Delta_{\text{R}}H^\circ{}$ again is the overall reaction enthalpy.  Since these estimations are based on some empiric data, they do not a substitute for an experimentally determined value for your newly prepared compound. Often, increment systems leave some of inter- and intramolecular interactions unconsidered (e.g., ring strain, possible existence of polymorphism) which then yields a difference between the estimated, and the actual value of $\Delta_{\text{R}}H^\circ{}$ or $\Delta_fH^\circ{}$.