SAJ14SAJ's answer is very good for the basic case. There are a few exceptions.
First, if you have an ingredient which is partly discarded, it can be hard or impossible to find out what part ended up in your final food. If you deep fry vegetables in oil, you will have to calculate the change in oil weight to find out how much oil got absorbed. Worse, if you soak cookies in milk, the cookies will absorb lots of whey, but no milkfat, and probably no lactose. On the other hand, some of the sugar in the cookies might get leached out into the milk. So, in this case, you can't get a good calculation even if you measure the amount of milk you throw out.
Second, if your cooking process involves fermentation, all bets are off. Yeast and bacteria will eat some of the carbohydrates, but not all. They will convert them to alcohol (which has calories) and carbon dioxide (which does not have human-digestible calories). It might be a small error in something like bread, where there are so many carbohydrates that the amount eaten by the short fermentation is noise. But if you are fermenting liquids with relatively little carbohydrates (kwass, alcoholic drinks), the result will be very different.
Third, alcohol also has calories (about 7 per gram). In most recipes, a part, but not all of it, evaporates during cooking. You can't control well for that, and it can make a significant difference in dishes with lots of alcohol, like coq au vin.
Fourth, the rule will hold for the macronutrients (carbohydrates, protein, fats) and their energy content (calories), as well as some stable micronutrients (predominantly trace minerals like calcium). Fragile micronutrients such as vitamins can break down during cooking. Also, if you are interested in a specific subtype of nutrient, that can also change. For example, you can start out with sucrose (table sugar) and end up with a mixture of glucose and fructose. This will still be the same total amount of carbohydrates, but for some diets, the difference in sugar type is important.