← Back to blog

The 3D Bin Packing Problem: Why It's Harder Than It Looks

· Updated · Stoa Logistics
stoapack algorithms engineering

You have items. You have boxes. Put the items in the boxes using as few boxes as possible.

Sounds simple. It’s not. The 3D bin packing problem is NP-hard, meaning there’s no known algorithm that can find the optimal solution in reasonable time for large inputs. Every bin packing system is making tradeoffs.

Why It’s Hard

Consider packing just 10 items into boxes. Each item can be rotated 6 ways (or 3 if you can’t flip it upside down). That’s potentially 6^10 = 60 million orientation combinations. For each combination, you need to figure out placement. And you need to try different box combinations.

Now scale to 50 items. Or 100. The search space explodes exponentially.

This is why most “bin packing calculators” cheat. They use simple heuristics that work okay for easy cases but fail badly on complex ones.

Common Heuristics (And Their Limits)

First Fit Decreasing (FFD): Sort items by volume, largest first. Put each item in the first box it fits. Simple, fast, often 20-30% worse than optimal.

Best Fit: Put each item in the box where it fits with the least wasted space. Better than FFD but still misses many optimizations.

Guillotine cutting: Divide the box into rectangular regions, place items in regions. Works well for 2D, struggles with 3D complexity.

Layer building: Fill the box in horizontal layers. Good for uniform items, poor for mixed sizes.

None of these consider the full 3D placement problem. They’re approximations that trade solution quality for speed.

What Makes Real-World Packing Harder

The theoretical problem is hard enough. Real-world constraints make it worse:

Weight limits: A box might have space for 20 items but can only hold 10 lbs. You need to track cumulative weight.

Fragility: Heavy items can’t go on top of light items. Some items can’t be rotated. Some can’t touch certain other items.

Stackability: Some items can bear weight, others can’t. You need to track what’s supporting what.

Box inventory: You don’t have infinite box sizes. You have the 5 sizes your warehouse stocks. The optimal packing might require a box you don’t have.

Multi-box optimization: Sometimes using 2 medium boxes is cheaper than 1 large box (dimensional weight pricing). The algorithm needs to consider total shipping cost, not just box count.

How StoaPack Approaches It

StoaPack uses a hybrid approach:

  1. Heuristic search: Start with fast heuristics to find a good-enough solution quickly
  2. Box re-selection: Repack eligible packages into smaller stocked boxes when the items still fit
  3. Multi-box consideration: Evaluate different box combinations, not just single-box packing
  4. Constraint satisfaction: Treat box weight limits, box and item stock, hazmat separation (each dangerous-goods item type in its own box), and supported hazmat quantity limits as hard constraints

For orders within StoaPack’s published limits, this finds a good plan quickly. It doesn’t promise the best possible plan, and each request has a 2-second packing budget.

The AI Layer

StoaPack also offers two optional AI features. Custom instructions turn a plain-language rule into a hard constraint. Supported rules are item separation, box assignment and a volume fill limit, for example “Pack the glass in box type B40.” If StoaPack can’t apply an instruction, the request fails instead of quietly ignoring it. AI review (ai_review: true, off by default) asks an LLM to review the algorithm’s plan. Either feature sends item, box and packing data to an external AI provider (Google Gemini or OpenAI). Leave both off and the packing runs without AI.

This isn’t AI doing the packing: the algorithm does the heavy lifting. AI only turns your plain-language rules into constraints, or reviews the plan when you ask it to.

Optimization Goals

Different operations optimize for different things:

Minimize boxes (minimize_boxes, the default, or minimize_boxes_then_volume, recommended for new integrations): fewest packages, and the smaller box when the count ties. Good for operations where labor is the bottleneck.

Minimize volume (minimize_volume): lowest total box volume, which tends to lower dimensional-weight charges. Package count can differ, so compare both.

Minimize cost (minimize_cost): ranks the box costs you supply, not carrier rates. A $0.50 small box might beat a $2.00 medium box even if it means 2 packages.

StoaPack lets you choose your optimization goal per request.

The Bottom Line

Bin packing looks simple but isn’t. Any solution is a tradeoff between computation time and solution quality. StoaPack aims for “very good solutions, very fast” rather than “perfect solutions, eventually.”

For most e-commerce operations, a very good plan right away beats a perfect plan in five minutes.


StoaPack is a 3D bin packing API with multi-warehouse support and AI review. Try it now.

Disclaimer

This content is for informational purposes only. Individual results may vary based on your specific circumstances.