Firewall is a security barrier between two networks that screens traffic coming in and out of the gate of one network to accept or reject connections and services according to a set of rules.
A firewall is like a secretary for a network which examines requests for access to the network. It decides whether they pass a reasonableness test. If they pass it they are allowed through and if not they are refused.
If a man wants to meet the chair of the community department, the secretary does a certain level of filtering but if the man wants to meet the President of the country, the secretary will perform a much different level of filtering.
A network firewall is placed between the internal network, which might be considered safe and the external network or the Internet which is known to be unsafe.
The job of the firewall is to determine what to let into and out of the internal network. In this way, a firewall provides access control for the network.
There are essentially three types of firewalls. Each type of firewall filters packets by examining the data up to a particular layer of the network protocol stack.
The firewalls are:
A packet filter is a firewall that operates at the network layer.
A stateful packet filter is a firewall that lives at the transport layer.
An application proxy is a firewall that operates at the application layer where it functions as a proxy.