Firewall is a device that is placed between a trusted (Higher security Zone / Inside Network) and an untrusted network (Low-security Zone / Outside Network) to provide security to users, servers, and internal network. It allows or denies traffic that is allowed to enter or leave the network according to pre-configured rules.
Network firewalls guard an internal LAN network from malicious access from the outside/unsecured zone, such as malware-infested websites or vulnerable ports. A Firewall also regulates inbound and outbound communications between devices.
It works at the Network (Layer 3), Transport (Layer 4), and Application layers (Layer 7) of the OSI Model.