What is a port and why your app needs one

Published on 2026-09-12 by frfrand

An IP finds the machine and the port, the program. What are the 65535 ports, why are those below 1024 special, and how to resolve an address already in use.

What is a port and why your app needs one

Short answer: a port is the number that indicates which program a connection goes to within a machine: the IP finds the server and the port finds the process. Your app usually listens on a high port (3000, 8000) on 127.0.0.1, and a reverse proxy like nginx publishes it on 443; that way the app is never directly exposed.

A machine has an IP address. But many programs run on that machine at the same time: a web server, a database, SSH, your application.

If a packet arrives at that IP, which one is it for?

That's what ports are for. The IP finds the machine; the port finds the program within it. The combination of both is called a socket, and it is what uniquely identifies a conversation on the network.

65535 doors per address

The port number is stored in 16 bits, so they range from 1 to 65535. That's a lot: no normal machine uses more than a few dozen.

They are divided into three ranges by convention:

  • 1 to 1023: the "well-known" ports. In Linux, for a program to listen on them it needs to be root (or have the CAP_NET_BIND_SERVICE capability).
  • 1024 to 49151: registered. Most databases and services live here.
  • 49152 to 65535: dynamic or ephemeral, according to IANA convention. From such a range comes the port that the system assigns to your side of the conversation when you open an outbound connection (Linux, by default, uses 32768 to 60999: see /proc/sys/net/ipv4/ip_local_port_range).

That last point explains something that confuses: when your browser connects to port 443 on a server, your own machine uses a random port from the high range. That's why you can have twenty tabs open against the same site without them mixing.

The ones worth knowing by heart

22 SSH 25 SMTP (outgoing mail) 53 DNS 80 HTTP 443 HTTPS 3306 MySQL 5432 PostgreSQL 6379 Redis

They are conventions, not rules. Nothing stops you from running your website on 8080 or moving SSH to 2222.

And a clarification worth mentioning: moving SSH from 22 to 2222 does not make you more secure. Automatic scanners test all ports equally. What it does do is leave your authentication log much cleaner, because the background noise from bots disappears. It's hygiene, not security.

Why your app runs on 3000 and not on 80

Because to listen on a port lower than 1024 you need to be root, and you don't want your application running as root.

The standard solution is to put a reverse proxy in front: nginx listens on 443 (starts as root, opens the port, and then drops privileges) and forwards requests to your app on localhost:3000.

Your app is never exposed to the Internet. Only nginx is.

Address already in use

The most common error with ports, and the easiest to resolve once you know the command:

$ ss -tulpn | grep :3000 tcp LISTEN 0 511 *:3000 users:(("node",pid=8412))

There you have the culprit with its PID. The flags are easy to remember: t for TCP, u for UDP, l for listening, p for process, n for numbers (without resolving names).

Almost always it's an old instance of your own application that didn't finish dying. kill 8412 and keep going.

If the command doesn't show the process, try with sudo: without privileges you don't see other users' processes.

Listening on 0.0.0.0 or on 127.0.0.1

This distinction is small to write and enormous in consequences.

127.0.0.1:5432 only accepts connections from the local machine 0.0.0.0:5432 accepts connections from anywhere

If your database listens on 0.0.0.0 and the firewall doesn't block it, it's open to the Internet. It's one of the most common ways to expose data without realizing it.

The rule: everything that doesn't need to come in from outside, should listen on 127.0.0.1. And if you need to connect from your machine, don't open the port: make an SSH tunnel.

In ArduMaker, from the Internet to a VPS only enters what you declare: a published domain or a TCP or UDP port redirection (when creating the VPS, additionally, SSH remains open for 6 hours). It's precisely so that this decision is explicit and not an oversight. A detail to keep in mind: a new redirection accepts connections from any IP, unless you set a policy that limits the origin.

What is a port and why your app needs one
What is a port and why your app needs one

Publishing an API without exposing all its ports

If your API listens on 127.0.0.1:8000, it only accepts local connections. You can put Nginx on port 443 to receive HTTPS and forward requests to that internal process. Opening port 8000 directly to the Internet is usually not necessary.

On an ArduMaker VPS you can associate a domain and manage the service. Document which ports must be public and keep PostgreSQL, Redis, or administrative tools internal unless there is a justified need.

Related: What is localhost · Linux Firewall.

Frequently asked questions

How many ports are there? 65535 per address, and TCP and UDP are counted separately. From 1 to 1023 are the well-known ones.

Why can't my app listen on port 80? Because on Linux ports below 1024 require root privileges, and it's not advisable for your app to run as root. The usual approach is to leave it on a high port and put nginx in front.

How do I see which process occupies a port? With ss -tulpn | grep :3000 (changing the number). Use it with sudo to also see other users' processes.

What is the difference between listening on 0.0.0.0 and on 127.0.0.1? 127.0.0.1 only accepts connections from the local machine; 0.0.0.0 accepts them from any interface. A database should almost always be on 127.0.0.1.

  • redes
  • puertos
  • TCP
  • fundamentos
  • servidores

Keep reading

All articles · VPS plans