The last slot is the focus slot
In a German sentence without special stress, the main accent falls on the last element before the closing verb. That slot is where the listener expects the new information. Moving a phrase into it or out of it is how German shifts the focus without extra words. English mostly keeps the order and moves the stress instead.
Same words, different news
Wir haben gestern gemütlich im Garten gefrühstückt.
We had a leisurely breakfast in the garden yesterday.
answers: Wo habt ihr gefrühstückt? The default order.
Wir haben gestern im Garten gemütlich gefrühstückt.
We had breakfast in the garden yesterday, and took our time over it.
answers: Wie war das Frühstück? The place is known, the manner is news.
The question decides the order
The same noun phrase can stand on either side of an adverbial, depending on what was asked. Test your order against the question it answers.
A
Wann hast du ihm den Schlüssel gegeben?
When did you give him the key?
B
Ich habe ihm den Schlüssel gestern Abend gegeben.
I gave him the key last night.
the key is known, the time is new
A
Was hast du ihm gestern Abend gegeben?
What did you give him last night?
B
Ich habe ihm gestern Abend den falschen Schlüssel gegeben.
I gave him the wrong key last night.
the time is known, the key is new
What does not move
Not everything is free. Two kinds of phrase belong so closely to the verb that they stay right in front of it, whatever the focus: a direction (wohin?) and a phrase that completes the verb's meaning, such as Bescheid in Bescheid sagen or ins Bett in ins Bett gehen. Reordering happens to the left of them. A plain location (wo?) is free to move.
Er hat die Akte aus Versehen auf meinen Tisch gelegt.
He put the file on my desk by mistake.
direction: stays next to the verb
Sag mir morgen früh bitte Bescheid.
Please let me know tomorrow morning.
Long phrases late
A long adverbial in the middle makes the listener wait for the verb. If the content allows, put the short elements first and the long one last, even if that breaks the default order.
Ich habe mit einer alten Schulfreundin, die ich seit Jahren nicht gesehen hatte, gestern lange telefoniert.
I had a long phone call yesterday with an old school friend I hadn't seen in years.
correct, but the listener waits a long time
Ich habe gestern lange mit einer alten Schulfreundin telefoniert, die ich seit Jahren nicht gesehen hatte.
I had a long phone call yesterday with an old school friend I hadn't seen in years.
short elements first, the relative clause after the verb