It is used to express an action that was completed before another action in the past:
I had not prepared for the test so I didn't pass it.
It is used to express an action that began in the past and continued to another action or point in time in the past:
When I left my job, I had lived in Glasgow for 3 years.
By New Year's eve, they had practiced jogging for 10 days.