A firewall can help block hackers or malicious software from infiltrating your computer through the internet or a network, as well as stopping your computer from sending malicious software to other computers.

Generally, there are two types of firewalls; a network firewall is a software appliance which runs on hardware which filters traffic between two or more networks, while a host-based firewall is a layer of software on one host that filters traffic on a single computer.

The first type of firewall was the packet filter, which were filter systems first developed by engineers from Digital Equipment Corporation.

These packets, which are messages transmitted over a packet-switching network, usually contain information of the packet's source, destination address, protocol and port number.

Packet filtering firewalls worked on the first three layers of the OSI reference model, meaning that the majority of the work was done between the network and physical layers.

One of a number of common firewall techniques, packet filter firewalls work at a low level of the TCP/IP protocol stack which use an established rule set as a means of blocking or allowing packets to pass into the network.

The text above is a summary, you can read full article here.