📐

FEFCO box die-line calculation in C++

a library and calculator for a cardboard packaging manufacturer

CompletedNDA
3 FEFCO styles
0200, 0201 and 0203 are calculated from one data structure, not separate tables
77.7%
of a 2000×1200 mm sheet used: 5 rotated blanks for a 300×200×150 box
0 dependencies
only a C++17 compiler and CMake, so the library embeds into production software

The task

A cardboard packaging manufacturer receives an order as the inner dimensions of a box: length, width, height. To cut the blank, it needs the size of the flat die-line, taking into account the board thickness, the glue flap and the fold allowances. To estimate material use, it needs to know how many such blanks fit on one sheet of corrugated board.

A die-line (blank) is the flat sheet that is cut and creased and then folded into a box. Creasing is a pressed fold line. Corrugated board is multi-layer cardboard with a fluted layer inside. FEFCO is the European catalogue of standard box designs, where every style has a code: 0201, 0203 and so on.

Spreadsheet calculations produced errors: board thickness is easy to forget, every style has its own formula, and sheet layout was estimated by eye. A mistake showed up only at cutting. The manufacturer needed a core that calculates by the catalogue rules and can be embedded into its production software.

The solution

A C++17 library called packaging and a command-line calculator, packaging_calc, built on top of it. What is implemented:

  • Three FEFCO box styles: 0200 (flaps on top only), 0201 (standard slotted box, flaps meeting with a gap), 0203 (full-overlap flaps).
  • Blank dimensions: length as 2L + 2W + glue flap + creasing allowances, width as height + flaps + allowances, and flap height.
  • Outer dimensions and two volumes: internal and overall.
  • Nesting of blanks on a board sheet, with a 90° rotation and the share of area used.
  • Input validation: positive dimensions, board thickness up to 20 mm, a valid flap gap. An error produces a message and return code 1.
  • Tests for the formulas, nesting, validation and style-code parsing, wired into CTest.
  • No external dependencies: only a C++17 compiler and CMake 3.14 or newer. It builds on Linux, macOS and Windows.

How it works

FEFCO 0201 die-line: the blank formula

The program fills in a BoxSpec structure (inner dimensions, thickness, glue flap, gap) and calls calculate() with a style code. The result is the blank: length, width, flap height and area. For 0201 the blank width is calculated from the gap between flaps, not from a fixed box width as in the prototype. Reference example from the README: a 300×200×150 mm box, 3 mm board, style 0201 gives a blank of 1047.0×356.0 mm, a flap of 98.5 mm and an area of 372,732 mm².

Creasing allowance and board thickness

Board thickness enters the calculation twice: as an allowance for each fold line and as an addition to the outer dimensions. The same box measures 306×206×156 mm on the outside, with an internal volume of 9.00 L; the overall volume is calculated separately from the outer dimensions. The creasing allowance is set equal to the board thickness. This is an approximation and may differ at a specific manufacturer, so the formulas need to be checked against the plant's tooling.

Nesting blanks on a corrugated sheet

The nest_on_sheet() function takes the blank and the sheet size, tries a grid layout in the original orientation and rotated by 90°, and returns the number of blanks and the share of sheet area used. On a 2000×1200 mm sheet the reference blank fits 5 times when rotated, with about 77.7% of the area used. The layout is a simple grid, and knife width is not yet taken into account.

Library and command-line calculator

The calculation plugs into another project as an ordinary CMake library: include the packaging/box.hpp header, fill in BoxSpec, call calculate() and, if needed, nest_on_sheet(). For manual checks there is the packaging_calc utility with parameters for style, dimensions, thickness, glue flap, gap and sheet; help is available with --help. Tests are run with ctest.

Results

  • Three FEFCO styles are calculated from one construction description, not from separate tables.
  • The blank, outer dimensions and volumes for the reference box match the expected values from the README; verified by building the project and running the tests.
  • Nesting returns the number of blanks and the share of sheet area used: 5 pieces and about 77.7% for a 2000×1200 mm sheet.
  • Invalid input is rejected with a clear message instead of producing a wrong drawing.
  • With no external dependencies, the library embeds into production software.

Technologies and why

  • C++17 — fast computation, and the code can be embedded into line software or a standalone service.
  • CMake — one command builds the library, the utility and the tests on any platform.
  • CTest — runs the tests for formulas, nesting and validation.
  • FEFCO — a shared language for describing box designs between the customer and the program.

Status

Version 0.2.0, released on 30 September 2026. The project has grown from a single-file prototype (0.1.0, February 2026) into a library, a utility and a test suite; board thickness now actually takes part in the calculation, and the 0201 blank width is calculated from the flap gap.

Next on the README roadmap: other FEFCO types, including 0427 and self-assembly boxes; corrugated board profiles and flute direction in nesting; knife width; exporting the die-line to DXF or SVG; cost calculation. Other details about the client are not disclosed.

Questions about this project

How do I calculate the blank size from the inner dimensions of a box?
You pass the length, width, height, board thickness, glue flap and flap gap. The library returns the blank length and width, flap height, area, outer dimensions and volumes. For a 300×200×150 mm box in 3 mm board, style FEFCO 0201, the blank comes out at 1047×356 mm.
Which FEFCO styles are supported?
Three catalogue styles: 0200 (flaps on top only), 0201 (standard slotted box, flaps meeting with a gap) and 0203 (full-overlap flaps). Other types, including 0427 and self-assembly boxes, are not implemented yet and are on the roadmap.
How many boxes fit on one sheet of corrugated board?
The nesting function takes the blank and the sheet size, tries placement in both orientations including a 90° rotation, and returns the number of blanks and the share of sheet area used. On a 2000×1200 mm sheet, the 0201 blank for a 300×200×150 box fits 5 times with about 77.7% of the sheet used.
How is board thickness taken into account?
Thickness goes into the creasing allowances and into the outer dimensions: a 300×200×150 box in 3 mm board measures 306×206×156 mm on the outside. The creasing allowance is set equal to the board thickness. This is an approximation and should be checked against the tooling of a specific plant.
Does the calculation need a server or spreadsheets?
No. It is a plain C++17 library with no external dependencies, built with CMake and linked directly into production software. For manual calculations there is a command-line calculator, packaging_calc, with the same parameters.
How can I check that the calculation is correct?
The repository has tests for the formulas, nesting, input validation and style parsing, run through CTest. Reference values for the 300×200×150 mm box are given in the README and were checked by running the code.

Need something similar?

Tell us about the task — we'll show how we solved it and estimate the scope.