Multiple twinning in cubic crystals is represented geometrically by a three-dimensional fractal and algebraically by a groupoid. In this groupoid, the variant crystals are the objects, the misorientations between the variants are the operations, and the Σ3n operators are the different types of operations (expressed by sets of equivalent operations). A general formula gives the number of variants and the number of Σ3n operators for any twinning order. Different substructures of this groupoid (free group, semigroup) can be equivalently introduced to encode the operations with strings. For any coding substructure, the operators are expressed by sets of equivalent strings. The composition of two operators is determined without any matrix calculation by string concatenations. It is multivalued due to the groupoid structure. The composition table of the operators is used to identify the Σ3n grain boundaries and to reconstruct the twin related domains in the electron back-scattered diffraction maps. © 2007 International Union of Crystallography - all rights reserved.