As far as I know there is no single answer to your question. They can work in a number of ways................for example there are hardware (device) firewalls and software ones.

This is quite comprehensive:

http://computer.howstuffworks.com/fr...firewalls-faq/

Now go to http://www.grc.com and run "shields up!" ....................not a totally definitive set of tests but if you fail any you probably ought to do something about it

Then go here: http://www.portmonster.com and get Portmonster by ZING Software.............it will keep you amused for a while and let you do a bit of experimenting. It has a nice GUI

Hope that helps.