A firewall monitors all incoming traffic and allows in only what is known or trusted. The traffic enters through "ports" on your PC. There are over 65,000 ports available under the Internet Protocol.
Firewall software restricts or grants access automatically by closing and opening ports as necessary. It also makes the computer "invisible" on the Internet so hackers will have a much harder time finding the PC.