We present a general method for obtaining the spectra of large graphs with short cycles using ideas from statistical mechanics of disordered systems. This approach leads to an algorithm that determines the spectra of graphs up to a high accuracy. In particular, for (un)directed regular graphs with cycles of arbitrary length we derive exact and simple equations for the resolvent of the associated adjacency matrix. Solving these equations we obtain analytical formulas for the spectra and the boundaries of their support.