A firewall is designed to prevent unauthorized access to or from a private computer network. It can be implemented in both hardware and software or a combination of both.

Firewall History
The computer firewall was first used in 1982 by Charlie Levy at the University of Southern California. Since then, various types of computer firewalls have evolved like stateful inspection firewall, circuit-level gateway etc., But all rely on basically same principle of inspecting packets (messages) entering and leaving the network for compliance with stated security policies.
In the early days of computing and networking, there were no firewalls or network security devices to prevent unauthorized access to computer networks. All messages entering or leaving a private network passed through a router which did not make any distinction between internal and external traffic (messages). This allowed anyone who had access to the routers and was able to exploit their weaknesses – either by guessing their addresses from where they originated or identifying other vulnerabilities in them – to gain unauthorized access.
This problem was addressed by creating separate firewall devices that could selectively block incoming packets originating from certain IP addresses while allowing others to pass through.
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 this firewall which examines each message and blocks those that do not meet the specified security criteria.
Hardware and Software
Firewalls can be hardware or software, but they all essentially do the same thing – check every bit of incoming and outgoing data for malicious code.
A firewall could be a physical piece of hardware that sits between the computer and the network, or it may just be part of another device such as a router. A software firewall lives on the machine itself and monitors all incoming data.
Hardware firewalls will generally offer more protection because there’s less chance for error than software, but both work essentially the same way – they keep out bad code. The most important thing about any firewall is updating them regularly so your protection isn’t compromised. Firewall manufacturers release updates and patches to protect against newly discovered threats every day. If you don’t update your system, then you aren’t getting any of the added protection when new threats are discovered.
Firewalls are also important for businesses. In addition to protecting the computers on the network, they can also be used to protect the business’ Internet connection from unauthorized access. Businesses should use hardware-based firewalls and not rely on the built-in firewall in their operating system.
Different Types of Firewalls
There are many different types of firewalls, but the most common are packet filters, stateful inspection firewalls, and application-level firewalls.
Packet filters are the simplest type of firewall. They filter traffic based on the information in the packets, such as the source and destination address and ports.
Stateful inspection firewalls are more advanced than packet filters. They keep track of the state of each connection and can filter traffic based on that information. For example, they can block all traffic from a particular IP address or all traffic to a certain port.
Application-level firewalls filter traffic based on the application that is using the port. For example, they can allow only traffic from HTTP ports 80 and 443 but block all other traffic. This is a common type of firewall for businesses that want to allow employees to use the Internet but protect their network from unauthorized access.
Firewalls can be a great way to protect your computer or network from unauthorized access, but they are not perfect. They can be bypassed if the attacker knows how to do it. And, they can’t protect you from malware that is already on your computer. For the best protection, you should use a firewall along with other security measures, such as antivirus software and anti-spyware software.