In The Dark Knight Rises, it is stated many times that it's 8 years after the end of The Dark Knight. This personally threw the storyline off for me. Why did it need to be 8 years after? 4 years would have surely been enough time difference for the storyline that played out.
Christopher Nolan's answer to the 8 year gap is:
It's partly about a physical and emotional toll and it's partly about being true to the end of [The Dark Knight].
What you have at the end of 'The Dark Knight' is an ending that hangs very much on substantial sacrifice to achieve a certain end and for that to have meaning, it has to work in some sense, it has to have been successful. And I didn't want to just abandon that and pick up a new story with a whole new set of ideas.
So for me, that lead to the 8 year gap, it lead to the idea of Bruce Wayne, shut away in self-imposed exile because he's hung up his cape and cowl. He's living in a world, at least superficially, that doesn't need Batman but he hasn't moved on, he hasn't moved on as Alfred points out, he hasn't moved on emotionally or in a practical sense.
He reiterates this in another interview:
... I think what we're saying is that for Batman and Commissioner Gordon, there's a big sacrifice, a big compromise, at the end of the 'The Dark Knight', and for that to mean something, that sacrifice has to work, and Gotham has to get better in a sense. They have to achieve something for the ending of that film—and the feeling at the end of that film—to have validity.
Their sacrifice has to have meaning, and it takes time to establish that and to show that, and that's the primary reason we did that.
It's a time period that is not so far ahead that we would have to do crazy makeup or anything—which I think would be distracting...
The last sentence sounds like he had thought about an even bigger gap, but decided against it because he wanted to avoid 'old people make-up'.
I think story-wise these things needed to happen:
The Harvey Dent Act had to have a real effect on Gotham's crime rate.
Harvey Dent himself had to become a legend.
The Batman's own legend had to fade away.
Talia al Ghul had to become old enough to be part of the story.
Whether 4 years would've been enough for all this to happen is debatable IMO, especially for the first part. Laws take a long time to have noticeable effects. So 8 years seemed reasonable to me.
While the internal plot-driven reasons in the previous answer make sense, there is another reason why the period was a long one.
Nolan's partial inspiration seems to have been the fantastic Frank Miller comic, The Dark Knight Returns (which also inspired the tone of the Tim Burton Batman movies and went some way to revivifying the whole Batman comic franchise) which has a long-retired Batman returning from his retirement due to serious new threats to the city. While the actual plot is very different, there are significant thematic similarities, including the fact that Batman is not as capable as he used to be and is facing a lead villain who is, in many ways, his equal. Much of the thematic similarity just would not have worked if Batman had returned too soon.