A firewall acts as a digital gatekeeper, monitoring and controlling network traffic based on predefined rules. It can block unsolicited incoming connections—like unexpected requests from the internet—while allowing outgoing traffic that a user intentionally starts, such as visiting a website. This helps protect devices and networks from unauthorized access without hindering normal online activities.

Most modern operating systems include a basic firewall that’s enabled by default, and many routers also serve as firewalls for entire home or office networks. These devices sit between the internet and connected devices, filtering traffic before it reaches users. However, firewalls do not scan files for viruses or prevent users from accidentally installing malicious software—those tasks fall to other security tools like antivirus programs.