An automatic inverse method has been developed for generating layered earth models from electrical sounding data. The models have the minimum number of layers required to fit a resistivity sounding curve or a combined resistivity and induced polarization sounding. The ground is modeled using a very large number of thin layers to accommodate arbitrary variations. The properties of the layers are optimized using as a constraint the L1 norm of the vertical derivative of the resistivity distribution. The use of linear programming leads to piecewise smooth distributions that simulate traditional models made up of a few uniform layers. The process considers from the simplest model of a uniform half-space to models of many layers, without fixing a priori the number of discontinuities. The solution is sought by iterating a new linear approximation, similar to the classical process of linearization, except that a reference model is not present in either the data vector or the unknown function. For induced polarization soundings, the problem is linear and the solution is obtained in a single iteration, provided an adequate resistivity model is available. The performance of the method is illustrated using numerical experiments and published deep resistivity data from Australia. The method also is applied to combined resistivity and induced polarization soundings from a local groundwater prospect in México.