You have a food name: from a search box, a barcode, a photo, or a line in a recipe. Now you need calories, macros, maybe micronutrients and allergens. It looks like a lookup table. It isn't.
Nutrition data comes from different databases built for different purposes. They report in different units under different national rules, and they treat missing values in different ways. This guide covers the problems teams hit most often, why each one is hard, and what to do about it. It points to free public resources wherever they're the right answer.
Why it's hard. There is no single "nutrition database". Every source is a trade-off between coverage, accuracy and licensing.
What to do. Decide what your users actually log. Mostly packaged goods: barcode plus a branded database. Mostly home cooking: a reference database like FDC Foundation/SR Legacy plus a recipe calculator. Mostly restaurants or mixed plates: you need either a menu database or an estimation layer, and this is where APIs like ours (or the commercial ones above) earn their cost. Many production apps use two or three sources with a clear priority order.
Why it's hard. Raw, roasted, grilled, skin-on, skinless, breaded, branded, and "chicken breast, rotisserie, store-bought": a text search returns dozens of entries, with calories that differ by 50% or more. Users pick the first one. The worst mix-up is between raw and cooked entries: dry pasta is about 370 kcal per 100 g, cooked pasta about 150. Pick the wrong one and your result is off by a factor of two to three.
Why it's hard. Databases store nutrients per 100 g. People log in cups, slices, pieces, handfuls, "a bowl". Converting needs a density or a standard portion weight for each food. A cup of flour is about 120 g spooned and 150 g packed. A cup of chopped kale weighs a fraction of a cup of cooked kale. "1 medium banana" depends on whose definition of medium.
Why it's hard. Developers often add a check that calculates calories from macros with the Atwater factors (protein × 4 + carbs × 4 + fat × 9) and expects the result to equal the label. They're surprised when real labels fail it. They're supposed to. In the US, label values follow FDA rounding rules (21 CFR 101.9). Calories under 5 are declared as 0, up to 50 are rounded to the nearest 5, and above 50 to the nearest 10. Fat under 0.5 g can be listed as 0 g. Manufacturers may also use any of several approved methods to calculate calories, including ones that subtract insoluble fibre.
Labels also have legal tolerances. For nutrients like calories, sugars, fat and sodium, the real value can be up to 20% above the label before it's out of compliance. For protein, fibre, vitamins and minerals, it must be at least 80% of what's declared. A label is a legal declaration within a tolerance, not a lab measurement.
If you need to produce a compliant panel rather than read one, our free nutrition label generator applies these rounding rules for you.
Why it's hard. Alcohol (ethanol) has about 7 kcal per gram and isn't protein, carbohydrate or fat. A calorie calculation using only 4/4/9 gives a 150 ml glass of wine about 16 kcal. The real figure is around 120 kcal, nearly all of it from roughly 14 g of ethanol.
What to do. Track alcohol in grams as its own nutrient and include it in energy as 7 kcal/g. If you're adding it to an existing API response, make the field conditional (present only when greater than zero). That way responses for every other food keep their current shape and existing clients don't break.
Why it's hard. If your app serves more than one market, identical field names hide different definitions:
| United States | European Union / UK | |
|---|---|---|
| Energy | kcal ("Calories") | kJ and kcal |
| "Carbohydrate" | Total carbohydrate, includes fibre | Excludes fibre |
| Fibre energy | Varies by calculation method | 2 kcal/g |
| Sodium | Declared as sodium (mg) | Declared as salt (g) ≈ sodium × 2.5 |
| Reference basis | Per serving (with "servings per container") | Per 100 g / 100 ml mandatory; per portion optional |
| Major allergens | 9, sesame added in 2023 | 14 (EU Regulation 1169/2011) |
Mix a US and an EU entry in one daily total and the carbohydrate number is wrong in a way no user will notice, which is especially bad for anyone counting carbs for diabetes.
What to do. Store values in one canonical internal format (for example: grams per 100 g, total carbohydrate including fibre, sodium in mg). Record which region each source comes from, and convert on the way in, not on display. "Net carbs" has no FDA definition, so if you show it, define your formula on screen.
Why it's hard. Branded and label-derived data contain only what the label must show. Since the 2020 US label update, that's vitamin D, calcium, iron and potassium, plus the macros. Vitamin C, magnesium and zinc are usually just absent. If your code treats absent as 0, a user eating oranges all day will see a vitamin C deficiency.
null for "unknown" and 0 for "measured as zero" throughout your schema, API and UI.Why it's hard. Allergen lists differ by country (see the table above). "May contain" warnings are voluntary in most markets, so their absence tells you nothing. A dish name never fully reveals its ingredients: pesto can contain nuts, and a curry may be thickened with wheat. A photo or name based system can only infer allergens, and a false "nut-free" is far worse than a false "contains nuts".
Why it's hard. The same calorie estimate means different things in different products. In a fitness tracker it's a wellness feature. In software that recommends an insulin dose from a meal's carbohydrates, it's input to a medical decision, and dose calculators are regulated as medical devices in the US and EU. At a typical insulin-to-carb ratio of 1:10, a 20 g carb error is 2 units of insulin. That's why clinical products carry a much heavier regulatory burden.
Privacy rules change too. In the US, HIPAA applies when you work with or on behalf of healthcare providers and insurers. A direct-to-consumer diet app usually falls under the FTC's Health Breach Notification Rule instead, which the FTC updated in 2024 to cover health apps explicitly. In the EU, health data is a "special category" under GDPR Article 9 and needs an explicit legal basis. Food photos and meal logs can count as health data when they're linked to a condition.
null for unknown, 0 for zero, everywhere.You can build all of this on free public data. USDA FoodData Central and Open Food Facts are excellent foundations, and for packaged food in particular you may not need anything else. An API like our nutrition API earns its place when users log meals rather than products: restaurant plates, home cooking, photos and free text. Then the hard part is turning something unstructured into numbers you can defend.
Labels are legal declarations within a tolerance, not lab measurements. Under US FDA rules, calories, sugars, fat and sodium can be up to 20% above the declared value, and protein, fibre, vitamins and minerals must be at least 80% of it. Values are also rounded, so calories calculated from the printed macros rarely match exactly.
About 7 kcal per gram of ethanol. Alcohol is not protein, carbohydrate or fat, so a calorie calculation that only uses 4/4/9 badly undercounts drinks: a 150 ml glass of wine is around 120 kcal, nearly all of it from roughly 14 g of ethanol.
For generic foods, USDA FoodData Central is free, public domain and lab-referenced. For packaged products worldwide, Open Food Facts is free and searchable by barcode under the ODbL licence. Many production apps combine both, plus a commercial or estimation API for restaurant meals and photos.
If you'd rather not build the estimation layer yourself, TastyAPI returns calories, macros, vitamins, allergens and dietary flags in about a second. 7-day free trial on every plan.
Get an API key