The link from MrM is very useful.
As a simple explanation for the beginning student, I recommend that one use when with the simple past and while with the past continuous. This is an oversimplification, but exposure to native writing and speaking will allow the individual to expand on it.