Network port: definition and meaning
A network port is a 16-bit number, 0 to 65535, that identifies an endpoint on a host for a transport protocol such as TCP or UDP. Together with the address it lets one machine run many network services at once.
What it is
A port is a 16-bit number carried in every TCP and UDP header, so it runs from 0 to 65535. An IP address picks the machine and the port picks the endpoint on it. A server binds an address and port and listens. A client connects from a short-lived source port that its operating system picks.
| Range | IANA name | Typical use |
|---|---|---|
| 0 to 1023 | System (also called Well-Known) | Standard services such as 22 (SSH) and 443 (HTTPS) |
| 1024 to 49151 | User (also called Registered) | Services registered with IANA, and the default ports of common dev servers such as 3000 and 5173 |
| 49152 to 65535 | Dynamic and/or Private (also called Ephemeral) | Never assigned by IANA; often used for short-lived outgoing connections |
These ranges are IANA’s, and operating systems do not have to follow them. Linux, for example, takes outgoing-connection ports from 32768 to 60999 by default, which starts below IANA’s dynamic range. On Linux, binding a port below 1024 also needs root or the CAP_NET_BIND_SERVICE capability by default, and the net.ipv4.ip_unprivileged_port_start setting can change that.
TCP and UDP are separate
TCP and UDP each have their own 16-bit port space, so TCP port 53 and UDP port 53 are different endpoints. The IANA registry lists DNS (domain) on port 53 as separate TCP and UDP entries, and on Linux a TCP listener and a UDP socket can hold the same port number at the same time. Dev servers usually speak HTTP over TCP, so a tool that says port 3000 usually means TCP port 3000.
One listener per address and port
On Linux, only one IP socket may be bound to a given local address and port pair. A second attempt fails with EADDRINUSE, which Node.js reports when another server is already listening on the requested port. The wildcard address 0.0.0.0 binds to all local interfaces, so on Linux a listener there also blocks a later bind to 127.0.0.1 on the same port. Socket options such as SO_REUSEADDR change these rules, and other operating systems can differ in the details.
// Ask the operating system for any free port, print it, then exit.
const server = require("net").createServer();
server.listen(0, "127.0.0.1", () => {
console.log(server.address().port);
server.close();
});In Node.js, port 0 means pick one for me: the operating system assigns an unused port, and you read it from server.address().port once the listening event has fired. That is how test suites avoid collisions. Free now does not mean free later: another process can take the port between your check and your bind.
In Rig
who_owns_portchecks whether a port is free by binding127.0.0.1and::. It useslsof -nP -iTCP:<port> -sTCP:LISTEN(netstat and tasklist on Windows) and returns each owner’s PID, command, name, and working directory.- It also suggests a free port: the first one from the wanted port plus 1 up to plus 50. The default search range is 3000 to 3999.
kill_portsends SIGTERM, waits 400 ms, sends SIGKILL if the port is still bound, then checks again. A project-scoped MCP token can only free that project’s own port.set_portonly stores a preferred port. It does not restart anything.start_projectwithresolve_portset tokillkills the owner. Set tosuggest, it switches the preferred port to a free one. Otherwise it returns a port conflict with the owner and a suggested port.- Rig starts Vite with
--port N --strictPort, Next.js with-p N, and Nuxt, Astro, and Remix with--port N. - Auto-restart frees an
EADDRINUSEport before it tries again. - Local HTTPS defaults to port 8443 and cannot go below 1024.
Related terms
- Glossary
EADDRINUSE
EADDRINUSE is the error code for “address already in use”. What it is, how it works, and a common confusion.
- Glossary
localhost
localhost is the reserved hostname for the machine you are on. What it is, how it works, and a common confusion.
- Glossary
Loopback address
A loopback address is an IP address that sends traffic back to the same machine. What it is, how it works, and a common confusion.
Sources
- IANA: Service Name and Transport Protocol Port Number Registry
- RFC 6335: IANA procedures for the port number registry
- RFC 9293: Transmission Control Protocol
- RFC 768: User Datagram Protocol
- Linux kernel documentation: IP sysctl
- Linux man page: ip(7)
- Linux man page: socket(7)
- Linux man page: bind(2)
- Node.js documentation: net
- Rig documentation: Common port conflicts (port checks, restarts, and local HTTPS confirmed in Rig’s source code)
See how Rig fits in
Rig is a Mac app that starts, stops, and watches the processes in a project from one window. The knowledge base explains each part in plain language.