A three-dimensional boundary element method was developed for optimizing the locations and impressed currents of electrodes in a cathodic protection system. The electrodes were regarded as the sources of current, and the potential in the electrolyte was described by the Poisson's equation with the boundary condition, in which the polarization of metal to be protected was taken into account. The Poisson's equation was solved by the boundary element method, and the optimization was performed by minimizing the power necessary to keep the potential on the metal surface below a critical value. An effective method is proposed for obtaining the derivatives of potential, which are needed in the optimizing procedure. In order to demonstrate the usefulness of the method, some example problems are presented.