To oversimplify greatly, -이/가 marks the grammatical subject of the main verb, whereas -은/는 marks the topic. Their use is mutually exclusive in the sense that you cannot attach both particles to the same word at the same time. It's even possible to have multiple subjects. There are all sorts of rules one can give for when to choose one over the other in terms of emphasis, contrast, etc. However, I would like to suggest that the best way to learn something like this is through experience and exposure to the language. Memorizing a bunch of rules out of your favorite Korean textbook for choosing one or the other probably isn't going to be very helpful. Probably not the answer you're looking for, but...
One small point I will add is that the grammatical subject in a Korean sentence is not necessarily the same as in other languages. When trying to understand the use of the subject marker in Korean, focus on understanding the Korean structure rather than trying to equate it to another language. As an easy example, "I need X" in Korean would be "나는 X이/가 필요하다." In the English version, X is a grammatical object of the verb "to need" whereas in Korean, it's the subject. If you translate the Korean phrase more literally, you're saying, "As for me, X i s necessary."