THE PLUPERFECT — the past before the past
Cuando llegué, ya se habían ido. When I got there, they had already gone. Spanish lets you stack pasts. One thing happened, and before that, another thing had already happened. Había plus the participle. That's the whole rule. What you do with it is the hard part.