We use the past perfect in the following two cases.
1) Past simple + past perfect
10 p.m. — I came home (starting point)
9:30 p.m. — My daughter went to bed
Some action happened in the past. For example, "I came home yesterday". This is our starting point on the timeline. Then, we have another action that completed before the first one started. For example, "When I came home, my daughter had already gone to bed."
So, we put the first action into the past simple and the second one which happened before — into the past perfect.
In sentences with "past simple + past perfect", we often use conjunctions such as "when", "before" and "after".
Jacob decided to go to Africa after he had watched a documentary about wildlife. 1) he watched a documentary; 2) he decided to go
I went straight to bed after the guests had left. 1) the guests left; 2) I went to bed
I hadn't truly loved anyone before I met you. 1) I didn't truly love anyone; 2) I met you
Had you consulted with your doctor before you started taking those pills? 1) you consulted; 2) you started taking the pills
If we have two actions in the past that happened one by one, like this
10:00 p.m. — I came home (starting point)
10:30 p.m. — I had a snack
then there is no need for the past perfect. We use the past simple tense for both actions. → I came home and had a snack.
The same is true for the actions that were happening at the same time. Like this
1:00 p.m. — I went shopping (starting point)
1:00 p.m. — My friends went to the cinema.
→ We arrived at the shopping centre. I went shopping, and my friends went to the cinema.
2) Present perfect for the past
The past perfect can also serve as an analogue of the present perfect for the past. See the explanation of the present perfect use.
Compare the present perfect with the past perfect:
Present perfect → Past perfect
The milk is fresh. I have checked the date on the bottle. → The milk was fresh. I had checked the date on the bottle.
Andrew has won the lottery. He can't believe it! → Andrew had won the lottery. He couldn't believe it!
It's the first time I have ridden a horse. → It was the first time I had ridden a horse.
I don't know the rules. I have never played this game before. → I didn't know the rules. I had never played this game before.