The subjunctive is a mood, not a tense, and it is used to describe attitude. It often expresses wish, fear, uncertainty, or hope.
"Que" is a good indication that the use of the subjunctive is required however its presence does not automatically mean the mood should be used. Some expressions such as "il faut que" will always be followed by the subjunctive. These need to be memorised by heart as there is no real alternative way of distinguishing them from the ones followed by the indicative. For example, "je veux que" is followed by the subjunctive but "j'espère que" is followed by the indicative.
Forming the subjunctive:All regular verbs follow the same pattern. Conjugate the verb in the present tense. Take the 3rd person plural (ils) and drop -ent. This is your subjunctive stem. Then add the appropriate subjunctive endings: -e, -es, -e, -ions, -iez, -ent.
Example: aimerj'aime / tu aimes / il aime / nous aimions / vous aimiez / ils aiment
There are also irregular verbs which do not follow this conjugation pattern.These include avoir, faire, pouvoir, valoir, among others. Unfortunately, their conjugations have to be learnt by heart.
Example: avoirj'aie / tu aies / il ait / nous ayons / vous ayez / ils aient