Here we define a theoretical basis for the generalization of the beam quality factor M2 to three-dimensional (3D) space, which we call M6 formalism. The formalism is established through the use of examples of multifocal and Axicon optical systems to illustrate discrete and continuous axial beam shaping, respectively. For the continuous case, we expand the definition of the Rayleigh range to incorporate a quality factor having both axial and transverse components $M_{{\rm{add}}}^2$ and M2. Using geometrical ray tracing simulations, a proportion factor C is found to empirically describe the axial quality factor $M_z^2$ of an optical setup including an Axicon and a paraxial focusing lens with a Gaussian single mode input beam. Using our M6 formalism depth of focus (DOF) ranges are calculated for higher M2 beams, and are shown to be in good agreement with the simulated DOF range, demonstrating the usefulness of the M6 formalism for the design of real optical systems.