Use 'if' in a sentence in which an event or situation might happen, might be happening, or might have happened.
Example:
If you see him tell him he still owes me one pound.
You use the word 'when' in a sentence in which an event or is certain to take place/happen or has recently taken place.
Example: