The data that your computer sends and receives over the internet, or an internal network is comprised of TCP packets and UDP packets. TCP packets can be more effectively filtered by firewalls because they contain more information in their headers.
TCP packets contain information such as source and destination addresses, packet sequence information, and payload. That information allows your network interface to deliver data properly, and a firewall can compare that information to the rules you configured it with. For example, all HTTPS data is transmitted through TCP packets.
When HTTPS data is sent to your computer through your network interface while you surf the web, your operating system will know that it's data that's supposed to go to your web browser. The same applies if you are surfing the web - on your phone, on your PC, or even on a server machine in your datacenter.
With the proliferation of the Internet of Things, you might even be surfing the web from a touchscreen embedded in your refrigerator. Your HTTPS data is used the same way regardless.
UDP packets can also be filtered by port, but their headers lack the information that TCP packets have for more sophisticated filtering.
Enjoy the graphic showing all that TCP Header contains...It is quite an useful depiction and you can learn a great deal about TCP.