This type of analysis is called elemental analysis. This is where a measured sample of an unknown compound is thermally combusted in the presence of excess oxygen gas in a sealed system to produce gaseous byproducts. The amounts of any gas byproducts produced are carefully measured and identified. Due to the law of conservation of mass, since the combustion takes place in a closed system, all of the non-oxygen atoms in the byproducts originated from the unknown sample. The oxygen could have originated from the sample or from the oxygen in the air so it cannot be determined. We can then calculate from how much of each byproduct was formed what the ratios and amounts of each of the elements present in the original sample was in order to determine what the chemical formula of the compound is. But the underlying scientific law that makes the whole thing possible is the law of conservation of mass.