# Port

> The numbered door on a computer that says which program a connection is for.

- Level: Intermediate
- Topics: Networks
- URL: https://tidbit.legios.com.ar/port/
- In Spanish: [Puerto](https://tidbit.legios.com.ar/es/port/)

An IP address gets a packet to the right computer; a **port** gets it to the right program on that computer. It is a number from 0 to 65535 that both TCP and UDP attach to every packet, next to the address. A server listens on a port, and anything arriving there is handed to the program behind it: a web server, a database, a mail server.

Many ports are conventions everyone follows. `80` is HTTP, `443` is HTTPS, `22` is SSH (remote terminals), `53` is DNS, `25` is email between servers, `5432` is PostgreSQL. When you type `https://example.com`, the browser silently uses port 443; a URL like `http://localhost:3000` is how a developer reaches an app running on port 3000 on their own machine. Your side of the connection also gets a port, a random high number, so the reply knows which browser tab it belongs to.

Ports are also where security starts. A firewall is, at its simplest, a list of which ports are open to whom: a web server exposes 443 and nothing else. An open port is a door that answers; scanning a server's ports is the first thing an attacker (or a security audit) does. Closing everything you do not use is the cheapest hardening there is.

## An analogy

An office building with one street address and many numbered doors. The mail arrives at the building (the IP address) and the number on the envelope (the port) says which office gets it.

## Keep in mind

- IP address = which machine; port = which program on that machine.
- Well-known ports: 80 HTTP, 443 HTTPS, 22 SSH, 53 DNS.
- A firewall decides which ports are reachable from outside.
- The browser hides the port when it is the standard one for the scheme.

## Go deeper

- [What is a computer port? (Cloudflare)](https://www.cloudflare.com/learning/network-layer/what-is-a-computer-port/)
- [Port (MDN glossary)](https://developer.mozilla.org/en-US/docs/Glossary/Port)
- [Port, computer networking (Wikipedia)](https://en.wikipedia.org/wiki/Port_(computer_networking))

## Related terms

- [IP address](https://tidbit.legios.com.ar/ip-address/): The number that identifies a device on a network, like a postal address.
- [Packet](https://tidbit.legios.com.ar/packet/): The small chunk every piece of internet data is cut into before it travels.
- [TCP and UDP](https://tidbit.legios.com.ar/tcp-and-udp/): Two ways to send packets: TCP checks everything arrives, UDP just sends and moves on.
- [Server](https://tidbit.legios.com.ar/server/): A computer whose job is to answer requests from other computers, all day, every day.
- [Database](https://tidbit.legios.com.ar/database/): An organized store of data that programs can search and update safely.
- [Email protocols](https://tidbit.legios.com.ar/email-protocols/): The shared rules, SMTP, IMAP and POP3, that carry an email from one inbox to another.
- [HTTP](https://tidbit.legios.com.ar/http/): The request-and-response language browsers and websites speak.
- [HTTPS](https://tidbit.legios.com.ar/https/): The padlock in your browser: web traffic nobody in between can read.
