What does System Restore really do?

Its' always been my option to use system restore when something messing up with my computer but the only idea I have regarding system restore is it will let you go back to your last configuration settings. I want to know more what actually happen when I use it.
Here’s my question:
1. Does using system restore make changes to my installed program which are installed after I set my restore point?
2. What is the thing that is being restored when I use it?
3. Is it really recommended to use it when something is wrong with my system? What would be the best scenario to use it?
4. When my system is infected by worms or virus and I use system restore could it be possibly deleted too?
5. How about my saved files, would it be affected and make any changes when I use it.
I think that’s all. I’m not knowledgeable when it comes to Computer.
I hope I can gain knowledge from your answer.
