What is the purpose of ports on a server?
An IP address finds the right machine; the port number then picks which application on that machine should handle the connection.
One server (one IP address) usually runs several network services at once — a web server, a mail server, a database. The IP address alone cannot say which of them an incoming connection is meant for. Ports solve this: each service listens on its own numbered port, so the address-plus-port pair routes the request to the right program.
Picture one host server.example.com running several services:
| Application | Port(s) |
|---|---|
| nginx web server | 80 (HTTP), 443 (HTTPS) |
| Tomcat web server | 8080 |
| Mail server | 25 (SMTP), 993 (IMAPS) |
| Print server | 631 |
Many protocols have a well-known standard port so clients know where to knock without being told:
| Port | Service |
|---|---|
| 22 | SSH |
| 80 | HTTP |
| 443 | HTTPS |
| 3306 | MySQL |
| 5432 | PostgreSQL |
Tip: because the standard port is implied, http://example.com quietly means http://example.com:80. You only spell out the port for non-standard setups like a dev server on :3000.