Firewall: A device that blocks traffic that meets certain criteria
Firewalls can operate at lots of different layers of the network. There are firewalls that can perform inspection of application layer traffic and firewalls that primarily deal with blocking ranges of IP addresses.
Firewalls are most commonly used in the transport layer. ex. UFW allow TCP 80.
Firewalls that operate at the transportation layer will generally have a configuration that enables them to block traffic to certain ports while allowing traffic to other ports.
For many companies and almost all home users, the functionality of a router and a firewall is performed by the same device. Firewalls can run on individual hosts instead of being a network device.
All major modern operating system have firewall functionality built in. That way, blocking or allowing traffic to various ports and therefore to specific services can be performed at the host level as well.