Abstract. In many problems in Computational Physics and Chemistry, one finds a special kind of sparse matrices, called banded matrices. These matrices, which are defined as having non-zero entries only within a given distance from the main diagonal, need often to be inverted in order to solve the associated linear system of equations. In this work, we introduce a new O(n) algorithm for solving such a system, with the size of the matrix being n × n. We derive analytical recursive expressions that allow us to directly obtain the solution. In addition, we describe the extension to deal with matrices that are banded plus a small number of non-zero entries outside the band, and we use the same ideas to produce a method for obtaining the full inverse matrix. Finally, we show that our new algorithm is competitive, both in accuracy and in numerical efficiency, when compared with a standard method based on Gaussian elimination. We do this using sets of large random banded matrices, as well as the ones that appear in the calculation of Lagrange multipliers in proteins.