Let us start with the basics: reported speech has to be in Konjunktiv. For instance:
Er sagt: "Ich gehe."
Er sagt, er gehe.
Notice that the Indikativ praesens is translated into an Konjunktiv praesens here. For the Praeteritum things get more complicated. We have to differentiate between the main sentence being in Praeteritum or the speech itself - or even both. Praeteritum in speech becomes Perfekt in reported speech:
Er sagte: "Ich gehe." - Er sagte, er gehe.
Er sagt: "Ich ging." - Er sagt, er sei gegangen.
Er sagte: "Ich ging." - Er sagte, er sei gegangen.
That was the basic part. Now things become somewhat tricky: one could swap out the Konjunktiv Praesens for the Konjunktiv Praeteritum:
Er sagt: "Ich gehe." - Er sagte, er ginge.
This is implying one of two things: either there is some condition to him going ("Er sagt, er ginge, wenn ...", he says he'd leave if ...) or the one reporting the speech has doubts about the truth of what was said. Here is a classical example from Schillers play "Wallenstein":
Mir meldet er aus Linz, er läge krank
He messages me from Linz he'd be ill
Would Wallenstein (the speaker) believe him he'd have said:
Mir meldet er aus Linz, er liege krank
But in fact he doesn't believe that for a moment. He continues, addressing Octavio Piccolomini:
Mir meldet er aus Linz, er läge krank;
Doch hab ich sich're Nachricht, daß er sich
Zu Frauenberg versteckt beim Grafen Gallas.
Nimm beide fest und schick' sie mir hierher.
He sends me word from Linz that he lies sick;
But I have sure intelligence that he
Secretes himself at Frauenberg with Gallas.
Secure them both, and send them to me hither.
(Translation by S. T. Coleridge from Project Gutenberg)
Wallenstein knows he is lying, but he trusts his intelligence about him being at Gallas' house.
This implication of doubt or prior conditions can also be done in Präteritum:
Er sagt: "Ich ging."
Er sagt, er sei gegangen. (I have no reason to doubt that.)
Er sagt, er wäre gegangen. (Allegedly, but I don't believe that really.)
Er sagt, er wäre gegangen. (He would have done so, would the conditions have been met, but - that is also implied - they weren't.)
Now we enter a really tricky area: if a Konjunktiv isn't noticeably being a Konjunktiv, which can happen with Konjunktiv Praesens, it is possible to use Konjunktiv Praeteritum instead. For instance, Goethe (quoted in the Sanders):
Da er hörte, daß ich viel zeichnete und [...].
Here "zeichne" would be korrekt but wouldn't be recognizable as Konjunktiv, which is why "zeichnete" - rightfully - stands in.