Airborne magnetic survey data sets can contain from hundreds of thousands to millions of observations and typically cover large areas. The large number of measurements combined with a model mesh to accommodate the survey extent can render an inversion of these data intractable. Faced with this challenge, we have developed a three-step procedure to locally optimize the degree of model discretization and to compress the corresponding sensitivity matrix for the inversion of magnetic data. The mesh optimization is achieved through the use of adaptive octree discretization. The compression is achieved by first reordering the model cells using the Hilbert space filling curve and then applying the one-dimensional wavelet transform to the corresponding sensitivities. The fractal property of the Hilbert curve groups the spatially adjacent cells into algebraically adjacent positions in the reordered model mesh and thereby maximizes the number of zero or near-zero coefficients in the one-dimensional wavelet transform. Winnowing these insignificant coefficients finally leads to a highly sparse representation of the sensitivity matrix, which dramatically reduces the required memory and CPU time in the inversion. As a result, the proposed algorithm is capable of inverting huge data sets ( measurements) with commensurate model sizes in a short time on a single desktop computer. As a test, we inverted an entire magnetic data set with 170,000 observations from a large uranium exploration program and achieved a reduction in computational cost exceeding 10,000 times.