A common mistake non-native speakers make is confusing these time words.

Ago vs. Before

‘Ago’ is used for things that happened before now. (one event vs. now)
‘Before’ is used for things that happened before another event (so the sentence must talk about two different events)

– examples
I came to Shanghai 5 years ago. (before now)
He graduated 20 years ago. (before now)

I came to Shanghai 2 months before he did. (two events – me coming to Shanghai, and him coming to Shanghai)
He graduated one year before she did. (two events)

In…time vs. After

The same rules work for the future.
In…time is used for when things that will happen from now (‘after now’).
After is used for things when compared to another event (so the sentence must talk about two different events).

(note: the word ‘time’ is often dropped from ‘in…time’)

– examples

I will change jobs in 3 months time. (3 months from now)
He will go home in 5 minutes. (5 minutes from now)

I changed jobs after he did. (two events)
He will go home after he finishes his work. (two events)  

Exercises

1. Answer these questions:
(i) What did you do 2 days ago?
(ii) What are you going to do in 5 hours time?
(iii) What did you do before you ate breakfast today?
(iv) What are you going to do after you retire?
2. Describe what you did/will do on these days:
(i) Today (using ‘ago’ and ‘in…time’)
(ii) Yesterday (using ‘before’ and ‘after’)