An iterative algorithm is described to solve the inverse problem of strati?ed media using magnetic ?eld data collected in aerial surveys. An airborne antenna sends downwards magnetic ?elds at several frequencies, and an airborne antenna detects the secondary magnetic ?elds. The input data for the inversion algorithm are the complex ratios between the secondary and primary magnetic ?elds at different frequencies. The algorithm selects one value for each unknown in ranges where the solution is likely to lie. Complex residuals between experimental and estimated data arecomputed.Acostfunctionisde?nedasthesummationoftheabsolutevaluesofthe real parts of the residuals added to the summation of the absolute values of the imaginary parts of the residuals. A value of the cost function is computed for the selected set of values of the unknowns. All such procedures are repeated for other sets of values of the unknowns. Such sets span the ranges of values where the solution is deemedtolie.Thesolutioninthe?rstiterationisthesetofvaluesoftheunknownsthat relates to the minimum computed value of the cost function. In each subsequent iteration, a minimization of the cost function is performed around the solution estimated in the immediately preceding iteration. The ?nal solution relates to the minimum value of the cost function over all the iterations. The inverse problem is solved without recourse to either analytical or numerical computation of derivatives. This providesstabilityandsimplicitytothealgorithm.TheMATLABcodeofthealgorithm is set forth. The code is assessed using ?eld data from two aerial magnetic surveys.