A firewall is a part of a computer system or network that is designed to block unauthorized access while permitting authorized communications.
It is a device or set of devices that is configured to permit or deny network transmissions based upon a set of rules and other criteria.
Firewalls are thus a specialized type of router focusing on specific types of network security functions.
Firewalls can be implemented in either hardware or software, or a combination of both.
Firewalls are frequently used to prevent unauthorized Internet users from accessing private networks connected to the Internet, especially intranets.
All messages entering or leaving the intranet pass through the firewall, which inspects each message and blocks those that do not meet the specified security criteria.
Courtesy :- http://en.wikipedia.org/wiki/Firewall_(computing)