To imagine the past being different (it didn't happen, and you can't change it now), use if + had + the past participle in the if half. This often carries regret or a gentle "if only".
Imagining a different past: if + had + past participle
I didn't study, so I failed. → If I had studied, I would have passed.
She didn't know, so she didn't come. → If she had known, she would have come.
We left late and missed it. → If we had left earlier, we would have caught it.
Not "If I would have known, I would have come." — say "If I had known, I would have come.". The if half uses had + the past participle (had known), not "would have".
Try it: Reality: I didn't study, so I failed. Build the if half about a past that didn't happen. (Leave out the word you don't need.) Answer: If I had studied, — The if half uses had + the past participle: If I had studied. "Would have" belongs in the other half (the result), not after if, so it's left out here.
The result: would have + past participle
The result half uses would have + the past participle. Both halves are about the past that didn't happen, so don't leave the have out.
would pass → would have passed
would come → would have come
would go → would have gone
Not "If I had studied, I would pass." — say "If I had studied, I would have passed.". The result needs would have + the past participle, not just "would".
Try it: If she had known ... Build the result half. Don't drop the have. (Leave out the word you don't need.) Answer: she would have come to the party. — The result uses would have + the past participle: she would have come. "Would" on its own drops the have and points to now, not the past that didn't happen, so it's left out.
Most regret is negative: hadn't / wouldn't have
Most third-conditional regret is about something that didn't happen. Make the if half negative with hadn't + the past participle, and the result negative with wouldn't have + the past participle. Either half (or both) can be negative.
I overslept, so I missed the train. → If I hadn't overslept, I wouldn't have missed the train.
She was rude, so we didn't invite her. → If she hadn't been rude, we would have invited her.
I didn't save my work, so I lost it. → If I had saved my work, I wouldn't have lost it.
Not "If I didn't oversleep, I wouldn't have missed the train." — say "If I hadn't overslept, I wouldn't have missed the train.". The past-negative in the if half is hadn't + the past participle (hadn't overslept), not "didn't".
Try it: Reality: I ate too much, so I felt sick. Build this regret as a negative on both sides. (Leave out the word you don't need.) Answer: If I hadn't eaten so much, I wouldn't have felt sick. — A past-negative in the if half is hadn't + the past participle (hadn't eaten), and a negative result is wouldn't have + the past participle (wouldn't have felt): If I hadn't eaten so much, I wouldn't have felt sick. "Didn't eat" is the wrong tense for imagining the past, so it's left out.
Asking about a different past: What would you have done if …?
To ask about an imagined past, put would before the subject: would you have + the past participle. A question word like What / How can go first. The if half still uses had + the past participle.
What would you have done if you had missed the flight?
Would you have come if she had invited you?
How would he have reacted if he had known the truth?
Not "What you would have done if you had missed the flight?" — say "What would you have done if you had missed the flight?". In a question, would comes before the subject: would you have done, not "you would have done".
Try it: Ask a friend about a past choice. Put the words in order to ask about a different past. (Leave out the word you don't need.) Answer: What would you have done if you had lost your job? — In a third-conditional question, would comes before the subject (would you have done) and the if half keeps had + the past participle (had lost): What would you have done if you had lost your job? "Did you have" is the wrong form, so it's left out.
Try it: Reality: we left late, so we missed the train. Put both halves together. (Leave out the word you don't need.) Answer: If we had left earlier, we would have caught it. — The if half is had + the past participle (had left), and the result is would have + the past participle (would have caught): If we had left earlier, we would have caught it. "Would leave" mixes will-style into the if half, so it's left out.