Difference between "dans" and "en"

Both words mean "in" how do I know which one to use in various contexts? Or, are they interchangeable?

They are not interchangeable. I think "dans " is used about delimited or precised space: "Je mange dans la salle à manger"." J'habite dans une grande ville" but we say: "J'habite en ville" "Je vis en France" "En" is used for a vast or general space. But French is very difficult and there are exceptions.
Please, excuse my english, I am French and I learn English

Looks like your connection to Home was lost, please wait while we try to reconnect.