What’s the difference between à and en?

Why is it “J’habite à Berlin.” but “J’étudie en Berlin.”? How do I know when to translate “in” as “à” and “en” ?