A firewall is designed to block problems.
In the traditional use of the word it was walls in a building that went from floor to roof and had no openings in them and thereby if the building caught on fire the fire would either be slowed by the firewall allowing the fire to be put out or would block the fire, in both cases saving part of the building
With computers and networks firewalls are designed to stop destructive things from either traveling thru the network or from getting on computers as a general definition.
Computer firewalls can either be programs, Microsoft and other software companies make software firewalls, or can be separate devices, two major firewall device makers are Cisco and Palo Alto.
The fire wall on a computer will block traffic entering the computer thru either blocking ports (you may have seen the number 80 after some web addresses, that says it uses port 80 and the web pages generally use port 80 or 453. There are thousands of ports. Different programs(applications) use different ports. Hackers will scan computers to find ports that are open and not used as ways to break in a computer thru the network. With the firewall you will close all ports you do not use and thereby block the hackers on many of their ways in. You can also block applications and block protocols. Protocols are rules to communicate with and web pages use http.
The firewall can also look at traffic coming across the network and look for malicious information and block it. Most often firewalls block traffic coming in to the network or computer, but you may set it up to block traffic going out. You may want to block all traffic from users that have not logged in your network or only allow them to the web server. Firewalls will do that. You also want to block malicious traffic from in your network so if machines get infected with malware they cannot phone home or go infect more machines.
Firewalls are important tools with cybersecurity and can be free and limited such as the Windows firewall or firewalls with some security suites, or extremely expensive like the top of line firewalls from Cisco and Palo Alto and other security equipment makers.