Skip to content

Localhost Ports Explained: Picking One for Dev Servers

Every developer eventually meets the error “address already in use”. Two projects both want port 3000, a forgotten container still holds 8080, and suddenly nothing starts. Ports are simple once you know how the numbering works and which ranges are meant for what. This guide explains the port system, lists the numbers you will bump into most often and shows how to pick a port that will not fight with anything else on your machine.

Options

Tip: press Enter or Space to generate again.

Ready

What a port actually is

An IP address identifies a machine; a port identifies one service on that machine. When your browser opens localhost:5173 in the address bar, it connects to your own computer and asks for whatever program is listening on port 5173. Ports are 16-bit numbers, so they run from 0 to 65535, and TCP and UDP each have their own separate set.

Only one program can listen on a given address and port at a time. That is why two dev servers configured for the same number collide.

The three official ranges

The Internet Assigned Numbers Authority (IANA) divides the space into three bands:

  • Well-known ports, 0–1023 — HTTP (80), HTTPS (443), SSH (22), DNS (53). On Linux and macOS, binding to them usually needs administrator rights.
  • Registered ports, 1024–49151 — assigned to specific applications, such as PostgreSQL (5432), MySQL (3306) and Redis (6379). MongoDB uses 27017.
  • Dynamic or private ports, 49152–65535 — never assigned to any service and intended for temporary and private use.

Operating systems also hand out short-lived “ephemeral” ports for outgoing connections; on Linux the default range starts at 32768, so very occasionally a random port in that area is briefly taken.

The usual suspects on a dev machine

Popular frameworks have default ports, which is exactly why they clash:

  • 3000 — many JavaScript frameworks and API starters
  • 5173 — the Vite dev server
  • 8000 — Python and PHP built-in servers
  • 8080 — a common alternative HTTP port for proxies and Java servers
  • 4200 — Angular’s dev server

If you run several projects at once, giving each its own fixed, unusual port saves you from guessing which app is answering on which tab.

How to pick ports with the generator

The generator above draws numbers from the range you choose:

  1. Select a range. The default, dynamic (49152–65535), is the safest for local servers, containers, test harnesses and SSH tunnels.
  2. Choose Any non-privileged (1024–65535) if you only need to avoid ports that require admin rights, or registered or well-known for parser and validation tests.
  3. Set how many ports you need — up to 100 per batch — for example one per microservice.
  4. Copy the list or export it as CSV or JSON for your compose file or environment template.

The tool cannot see your machine, so check that a port is free before you bind to it.

Fixing “address already in use”

Find out which process holds the port, then stop it or move your app:

  • macOS and Linux: lsof -i :3000 lists the process and its PID.
  • Linux alternative: ss -ltnp shows every listening TCP port.
  • Windows: netstat -ano | findstr :3000 prints the PID to look up in Task Manager.

In automated tests, many frameworks let you bind to port 0, which asks the operating system for any free port — handy when tests run in parallel.

Ports in Docker and containers

Containers add one more layer. A service inside a container listens on its own internal port, and you publish it to your machine with a mapping such as -p 51234:80: the left number is the port on your computer, the right one is inside the container. This means several containers can all use port 80 internally while each gets a different host port.

A few habits keep multi-container setups tidy:

  • Choose host ports from the dynamic range so they never collide with local databases or other dev servers.
  • Keep the mapping in your compose file, not in a command someone has to remember.
  • Publish only the ports you really need to reach from outside; containers on the same network can talk to each other directly.
  • Remove stopped containers regularly, since a forgotten one may still hold a port.

Pro tips

  • Store each project’s port in an environment variable instead of hard-coding it.
  • Pick dynamic-range ports for anything you expose only on your own machine.
  • Bind dev servers to 127.0.0.1 unless other devices really need to reach them.
  • Write the port in the project README so teammates do not have to guess.

Frequently asked questions

Why does port 80 need admin rights?

On Unix-like systems, ports below 1024 are privileged so that only trusted processes can claim the standard service ports. Development servers therefore usually use higher numbers.

Do TCP and UDP share port numbers?

They use the same numbering but separate tables, so a TCP service and a UDP service can both use port 5000 on the same machine.

Is localhost:3000 visible to other people?

Only if the server listens on an external network interface and your firewall allows it. A server bound to 127.0.0.1 is reachable from your computer alone.

Try a generator

Random Address Generator

Realistic street addresses with valid-format postal codes and phone numbers for 40 countries.

Fake Identity Generator

Complete fictional person profiles: name, birthday, address, phone, email, job and more.

Need random data? Get it now.

Pick any of 144 generators, hit Generate and copy or export the results as CSV, JSON or TXT. No account, no limits, nothing stored.

Start generating — free