There are a lot of rules, unfortunately. Even Koreans don't know all of them because they usually just use one or the other naturally. But basically,
1. Use 은/는 if introducing yourself.
ex. 나는 외국사람이다.
2. Use 은/는 if comparing. This is much more confusing than expected, though. I can't explain with great confidence because I don't know if I can explain it correctly. ㅜㅜ
ex. 이 산이 높다. 저 산은 낮다.
ex. 한국어를 할 줄 안다. 영어는 못 한다.
3. Use 이/가 if describing something (take note of 1. and 2.).
ex. 이 산이 높다.
4. For compound sentences, use 이/가 to the subject of the less important clauses and use 은/는 to the most important clause (i.e. where the topic really is). 은/는 is usually used in the last clause, unless the subject of the first clause and the last clause is the same. In that case, you may not write a subject in the last clause, and use 은/는 in the first clause for simplicity.
ex. 내가 이기면 너는 밥을 사야 된다.
Just think of 이/가 as the "subject marker" and 은/는 as the "topic marker".
은/는 can also take over 을/를, 에/에서 (-> 에는/에서는), 을 때 (-> 을 때는), 으면 (-> 으면은), etc. especially if you want that part to be the topic of what you want to write/speak. (see second ex. of 2.)
I hope I am making sense even just a little bit and I hope someone who is more knowledgeable will explain this later on :)