A firewall is a device or software that protects private networks from unauthorized access. Hardware firewalls protect entire networks at the router level while software firewalls protect individual computers. There are three main types of firewalls: packet filtering routers inspect packets and allow or block them, application-level gateways act as proxies for applications, and circuit-level gateways set up two TCP connections to determine which connections are allowed. A firewall establishes rules to allow trusted traffic to flow automatically while blocking dangerous traffic to protect computers and networks.