Let me start by saying I'm not a nutritionist, so let's get that out of the way. What I can tell you is I've spent decades backpacking and mountaineering and have tried a lot of different foods. Back in the 70's my father actually perfected a backpacker oven. It was attached to a Bleuet canister stove (the picture there on the left)...the early version of canister type (BRS and PocketRocket) stoves. Not to digress into stoves; the point is an oven means cookies, cakes, and cinnamon rolls which sounds great but isn't healthy, weighs a ton (flour, sugar, etc.) and is loaded with unnecessary carbs.
Long story short, as a 13 year old that probably weighed no more than 125 pounds, I was faced with the unfortunate task of carrying a 60 pound pack cross country for a 16 day mountaineering expedition into the Sierra's. Obviously that's something you want to avoid. Fortunately, since those days backpacking food producers have found a way to package good food into much lighter packaging. Still, I marvel at the unhealthy options hikers seem compelled to pack for their hikes...even without the oven. I'm not here to blast this type of fare. To each his or her own but I'd simply point out that recently Outdoor Magazine wrote an article dispelled the assumption that you can keep healthy while hiking even eating junk food. So it's at least something to consider when packing those Frito's or Snickers bars into your pack
Calories Per Ounce - The Magic Target Broadly speaking the best approach I've found to preparing (regardless of prepackaged food or a DYI approach) is to focus on macros and calories per ounce. The Magic Target I use is 135 calories per ounce. This isn't always attainable but it should be your goal. Some argue the target should be as high at 150 calories per ounce and I agree, if you can get there that's a fantastic goal and probably the lens with which you should consider including a food into your meal plan. Still, I've found that 150 calories/ounce a difficult bar to hit. This is an important tool since the more calorie dense your choices the less weight you'll carry to meet your caloric needs while on the trail. BTW, I should point out that a trail favorite, the Snickers Bar, fits into the 135 calories/ounce goal but may not be the healthiest choice and I won't get into the chocolate mess you'll get if you pull this out on a hot summer day. Another trail favorite, Frito's, also fits the calories per ounce bill at a massive 160 calories/ounce but again, nutritionally Frito's aren't a great choice (corn and artery clogging corn oil) not to mention the corn chip mess you'll get after you cram these into your pack.
Again, I'm not a nutritionist but let's start with what the USDA 2020 dietary recommendations are for percentage of calories from each macro (Protein, Carbohydrates, and Fats). Per the UDSA calories from each group should average:
If you're on a short backpack; anything less than 3 or 4 days I'd stick with these recommendations. Adjust for your individual needs. Obviously if you're on a Keto diet your carbs will be below the USDA recommendations and fats will be higher but you get the idea.
If you're heading out for a week long backpack or maybe a long thru-hike you're going to want to make some adjustments. Your adjustments however should be tuned based on the type of hiking you're planning on. If you're "Destination Hiking" (shorter hikes, more camping) you may not want to adjust much but I do suggest increasing your fat and protein and reducing the carbs. You'll be more active than at home or behind a desk and your days will involve longer stretches of low intensity exertion. Without getting technical, fats and proteins are better suited for long duration, low intensity exercise.
If you're a "hiker" or a trekker and your day involves early morning starts, hiking all day and into early in the evening then you seriously need to consider increasing your fats and proteins and reducing your carbs. You'll be pushing your body all day and the short term energy of carbs won't be enough. If you're not fueling your body with long burning fats and protein then your body will get the fuel it needs elsewhere and that might mean burning muscle mass. Increasing protein and fats will help avoid or at least reduce loss of muscle mass and help fuel the long duration work you'll be asking your body to deliver.
Avid backpackers rightfully complain about the high cost of prepackaged freeze dried meals. Most meals on the market cost over $10 and often approach $15. Most are marketed as "2 serving meals" but let's be honest, nearly every backpacker I've ever hiked with eats the entire package. So at $10 to $15/serving prepackaged meals can make hiking expensive.
The two alternatives I've seen hikers use to attack this problem are: