We elucidate the mechanism of a newly observed photovoltaic effect which occurs in ferroelectrics with periodic domain structures. Under sufficiently strong illumination, domain walls function as nanoscale generators of the photovoltaic current. The steps in the electrostatic potential function to accumulate electrons and holes on opposite sides of the walls while locally reducing the concentration of the oppositely charged carriers. As a result, the recombination rate adjacent to the walls is reduced, leading to a net diffusion current. In open circuit, photovoltages for periodically ordered domain walls are additive and voltages much larger than the band gap can be generated. The internal quantum efficiency for individual domain walls can be surprisingly high, approaching 10% for above band-gap photons. Although we have found the effect in BiFeO3 films, it should occur in any system with a similar periodic potential.