How do they determine the nutritional facts of foods?
You can do it via the method prescribed in words o wisdom’s answer, or you can do it another, more accurate way… A sample of the food is taken from the finished product, then mashed up (using a machine called a digester), then many different tests are performed depending on what you are testing for. There are different chemical experiments for protein, carbohydrates, fat, vitamins, minerals, water content and water activity, as well as total calorie value. The results of these tests are then extrapolated using maths to determine the values for a serve of a particular food. If you would like to know some of the names of the assays used to determine these values, let me know and I will add more to this answer.