The past perfect tense is used to describe an action (or event) that happened before another action (or event) happened. The past perfect is formed by combining the past tense of ‘have’ with the past participle of the verb.
had (not) + past participle
He had gone to the store
We had visited our parents
I hadn’t worked for this company
A complete sentence using the past perfect tense combines a clause formed with the past perfect tense plus a clause formed with the simple past tense. (Review how to form the simple past by reading this post.)
The two clauses are most often joined with the conjunction before, but others can be used, such as when and by the time.
had + past participle + before + simple past
I had worked for this company for five years before you started.
I had worked for this company for five years by the time you started.
I had worked for this company for five years when you started.
The order of the two clauses doesn’t matter because the action described using the past perfect tense is always the first action and the action described using the simple past tense is always the second action.
Before you started, I’d worked for this company for five years.
Had you eaten before I cooked dinner?
Had you been to New York before you went last year?
How many times had you fixed your car before it finally broke down?
Why hadn’t you cleaned your room before I got home?