In casual use, they are often interchangeable. In careful use, "when" is usually associated with a static description or a completed action, and "while" with an ongoing action. However, there is considerable variation in usage.
WHEN you phoned me, I was working in the garden.
I was working in the garden WHEN you phoned me.
WHILE I was working in the garden, you phoned me.
You phoned me WHILE I was working in the garden.
When I was in France, I visited the Louvre.
While I was traveling in France, I visited the Louvre.