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.

Updated

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.

RangeIANA nameTypical use
0 to 1023System (also called Well-Known)Standard services such as 22 (SSH) and 443 (HTTPS)
1024 to 49151User (also called Registered)Services registered with IANA, and the default ports of common dev servers such as 3000 and 5173
49152 to 65535Dynamic 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.

JavaScript
// 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_port checks whether a port is free by binding 127.0.0.1 and ::. It uses lsof -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_port sends 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_port only stores a preferred port. It does not restart anything.
  • start_project with resolve_port set to kill kills the owner. Set to suggest, 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 EADDRINUSE port before it tries again.
  • Local HTTPS defaults to port 8443 and cannot go below 1024.

Sources

  1. IANA: Service Name and Transport Protocol Port Number RegistryOfficial documentation, checked 13 October 2026
  2. RFC 6335: IANA procedures for the port number registryOfficial documentation, checked 13 October 2026
  3. RFC 9293: Transmission Control ProtocolOfficial documentation, checked 13 October 2026
  4. RFC 768: User Datagram ProtocolOfficial documentation, checked 13 October 2026
  5. Linux kernel documentation: IP sysctlOfficial documentation, checked 13 October 2026
  6. Linux man page: ip(7)Official documentation, checked 13 October 2026
  7. Linux man page: socket(7)Official documentation, checked 13 October 2026
  8. Linux man page: bind(2)Official documentation, checked 13 October 2026
  9. Node.js documentation: netOfficial documentation, checked 13 October 2026
  10. Rig documentation: Common port conflicts (port checks, restarts, and local HTTPS confirmed in Rig’s source code)Rig source code, checked 13 October 2026

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.

Related

https://userig.app/glossary/network-port