Put a white pawn on e5 and let Black play d7-d5. Now exd6 is legal. Slide that white pawn back to e4 and play the same d7-d5: nothing at all, the pawn on d5 is untouchable. The rank your pawn is standing on decides everything, and it is the condition beginners forget first.
Condition by condition
Your pawn is on its fifth rank. That is rank 5 for White and rank 4 for Black, counted from your own back rank in both cases.
The enemy pawn moves two squares in one move, from its home rank. Two single steps do not count, however recently they were played.
It lands directly beside your pawn, on an adjacent file. Same rank, next file along, no gaps.
You capture on your very next move. Not two moves later, not after a check in between.
When all four hold, your pawn moves diagonally forward onto the square the enemy pawn crossed, one rank behind where it actually stopped, and that pawn is lifted off the board. Beginners stare at this because the captured piece is not standing on the square the capturing pawn ends up on. It is the only capture in chess that works that way.
Black’s version, on the fourth rank
Same rule, mirrored. Here Black has a pawn on e4 and White has just played d2-d4.
1
2
7
h
g
f
e
d
c
b
a 8 The move is exd3. Black’s pawn goes to d3, White’s pawn leaves d4, and Black now has a pawn two squares from promotion sitting in the middle of White’s camp. This is the version that turns up in real games far more often than the White one, because pushing d2-d4 or f2-f4 to challenge an advanced enemy pawn is such a natural idea.
Three ways to lose the right
You played something else first. One move is the whole window.
The pawn arrived in two steps. A pawn that went d7-d6 and later d6-d5 has already offered itself on d6, and you declined.
Your pawn is on the wrong rank. A pawn on e4, e6 or anywhere else has no claim, however close it looks.
There is a fourth trap that is not about timing: the capturing unit must be a pawn of yours. A rook or a king standing beside the arriving pawn does nothing, which is covered on whether any piece can capture en passant. And once all of it is clear, taking is still optional unless it happens to be your only legal move.
Everything above sits in Article 3.7 of the FIDE Laws, the pawn article, in a couple of sentences. Reading it once is worth it. Then go and solve a dozen en passant puzzles, because the rule sticks through the fingers rather than the eyes.