When you want to talk about something that did not happen in the past, and imagine what might have happened had some condition been different, you need a form that ordinary German tenses cannot supply — because the Präteritum and the Perfekt describe what actually occurred, not what was merely supposed to occur. This gap is filled by Konjunktiv II der Vergangenheit, the form native speakers reach for to express regret, reproach, belated advice, and unreal conditions set in the past — everything captured by patterns like "if only... had," "should have," or "would have."
The temporal logic here matters and differs sharply from the present-tense Konjunktiv II. Wenn ich Zeit hätte, würde ich kommen describes a possibility still open in the present or future. Wenn ich Zeit gehabt hätte, wäre ich gekommen closes that door for good: the time has passed, the opportunity is gone, and nothing can change the outcome now. This distinction between "still possible" and "too late" is the essence of what separates the past form from its present-tense counterpart.
Structurally, the form is always built from an auxiliary in Konjunktiv II plus a Partizip II: hätte with most verbs, wäre with verbs of motion or change of state (gehen, kommen, werden) and with sein and bleiben. Conceptually it is simply the Plusquamperfekt (hatte/war + Partizip II) with the auxiliary shifted into its subjunctive form.
The trickiest case arises when a modal verb is present: instead of hätte gemusst, German uses the so-called Doppelinfinitiv, in which the modal itself stays in its infinitive form at the very end of the clause: Ich hätte früher kommen sollen ("I should have come earlier, and did not"). Word order shifts accordingly — hätte takes its normal second position while the two infinitives (main verb + modal) move together to the end of the clause.
This leads to the mistake advanced learners make most often: confusing hätte kommen sollen (regret over a past action that was never carried out) with sollte kommen (present or future advice or obligation whose outcome is still undetermined). The first sentence tells you unambiguously that the person did not come and regrets it; the second carries no such temporal closure. A second common error is reaching for würde + Infinitiv II (würde gekommen sein) instead of the simpler and correct hätte/wäre + Partizip II — a construction that is rare and unnatural in careful writing and speech.