This is a very common question amongst all Spanish-learners and sadly there isn't an answer that is completely 'set in stone'. This is because the subjunctive doesn't exist in English, which means it is difficult for us, as English-speakers, to identify when we need to use it. While this can be frustrating, there are a few key things to look out for and help you decide when to use the subjunctive.
First of all, what exactly is the subjunctive? It is not a tense; it is a 'mood'. It can be used in a variety of tenses (such as present, imperfect and perfect) and is used when we want to express certain feelings. To remember when to use it, we can think about the acronym WEIRD (Wishes, Emotions, Impersonal expressions, Recommendations, Doubt/Denial). Whenever you want to express wishes, emotions, impersonal expressions (such as 'es necesario que' or 'es posible que'), recommendations, doubt or denial, it is probable that you will need to use the subjunctive.