Abstract. Classical Schwarz methods and preconditioners subdivide the domain of a partial differential equation into subdomains and use Dirichlet transmission conditions at the artificial interfaces. Optimized Schwarz methods use Robin (or higher order) transmission conditions instead, and the Robin parameter can be optimized so that the resulting iterative method has an optimized convergence factor. The usual technique used to find the optimal parameter is Fourier analysis; but this is only applicable to certain regular domains, for example, a rectangle, and with constant coefficients. In this paper, we present a completely algebraic version of the optimized Schwarz method, including an algebraic approach to find the optimal operator or a sparse approximation thereof. This approach allows us to apply this method to any banded or block banded linear system of equations, and in particular to discretizations of partial differential equations in two and three dimensions on irregular domains. With the computable optimal operator, we prove that the optimized Schwarz method converges in no more than two iterations for the case of two subdomains. Similarly, we prove that when we use an optimized Schwarz preconditioner with this optimal parameter, the underlying minimal residual Krylov subspace method (e.g., GMRES) converges in no more than two iterations. Very fast convergence is attained even when the optimal transmission operator is approximated by a sparse matrix. Numerical examples illustrating these results are presented.