Kohn–Sham density functional theory (KSDFT) is the most widely used electronic structure theory for condensed matter systems. The standard method for solving KSDFT requires solving N eigenvectors for an O(N) × O(N) Kohn–Sham Hamiltonian matrix, with N being the number of electrons in the system. This procedure is expensive and scales as O(N3). We have developed a pole expansion plus selected inversion (PEpSI) method, in which the KSDFT is solved by evaluating selected elements of the inverse of a series of sparse symmetric matrices, and the overall algorithm scales as at most O(N2) for all materials including metallic and insulating systems. Recently we generalized the new method to nonorthogonal basis sets, with the electron density, total energy, Helmholtz free energy and atomic force calculated simultaneously and accurately. Combined with atomic orbital basis functions, the new method can be applied to study the electronic structure of boron nitride nanotube and carbon nanotube with more than 10,000 atoms on a single processor.