Internet Basics & History

Ports Explained: How One Computer Runs Many Services

Learn what port numbers do, which ones you meet most, how to see what is listening on your computer and when to worry.

Key takeaways

  • An IP address identifies a machine's network interface; a port number identifies a service or conversation on it.
  • Servers listen on agreed ports, while clients usually use temporary ones picked by the operating system.
  • TCP and UDP have separate port spaces, so the same number can be used by each.
  • A port is only reachable if a program is listening and nothing in between blocks it.

A port is a number that tells a computer which program should receive incoming network data. The IP address gets traffic to the right machine, and the port gets it to the right service on that machine, which is how one server can handle web pages, email and remote logins at the same time.

Ports aren't physical sockets like the ones for cables. They're 16-bit numbers in the TCP and UDP headers, ranging from 0 to 65535.

The apartment building analogy, and its limits

Think of the IP address as a building's street address and the port as an apartment number. The mail carrier needs both. Without the apartment number, a letter reaches the lobby and stops.

The analogy breaks down in one useful way: an apartment holds one household, while a single listening port can serve thousands of visitors at once. The reason lies in how connections are identified.

How one port serves many visitors

A TCP connection is identified by four values: source address, source port, destination address and destination port. A web server listens on port 443. Two browsers connect to it, or two tabs on your own computer do, and each connection arrives from a different source port. The four-value combination is unique, so the server never confuses them.

One server, several listening ports (typical numbers)
192.0.2.10 One address; the port picks the service. 443 HTTPS, and HTTP/3 over UDP. 80 Plain HTTP, often a redirect. 22 SSH remote administration. 25 Mail arriving from other servers. 53 DNS queries over UDP and TCP. 192.0.2.10 One address; the port picks the service. 22 SSH remote administration. 25 Mail arriving from other servers. 53 DNS queries over UDP and TCP. 80 Plain HTTP, often a redirect. 443 HTTPS, and HTTP/3 over UDP.

When you type a web address, the browser assumes the default port: 80 for http and 443 for https. A different port has to be written out, as in http://example.com:8080/. The parts of an address are taken apart in URL anatomy.

The three ranges

IANA keeps a public registry of port numbers and service names, and RFC 6335 describes the ranges.

Range Name Typical use
0 to 1023 System (well-known) ports Long-established services; many systems require elevated rights to listen here
1024 to 49151 User (registered) ports Applications that have registered a number, and many that simply picked one
49152 to 65535 Dynamic (private) ports Temporary use

The temporary port a client uses is called an ephemeral port. Operating systems differ in which range they draw from, and some use a wider span than IANA's dynamic block, so don't be surprised by a client port in the 30,000s or 40,000s.

Registration is a convention, not an enforcement mechanism. Nothing stops a program from running a web server on port 22. The registry just lets software and people agree on where to look.

Ports worth recognizing

Port Service Note
20, 21 FTP Old and unencrypted in its basic form
22 SSH and SFTP Encrypted remote access
23 Telnet Unencrypted; should not be exposed
25 SMTP Server-to-server mail
53 DNS UDP for most lookups, TCP too
67, 68 DHCP Address assignment on local networks
80 HTTP Unencrypted web
123 NTP Clock synchronization
443 HTTPS Encrypted web
465, 587 Mail submission Your mail app sending through your provider
993 IMAP over TLS Reading mail
995 POP3 over TLS Downloading mail
3389 Remote Desktop Frequently targeted when exposed

Listening, open, closed and filtered

A program that wants incoming traffic asks the operating system to bind to a port and listen. Two programs generally can't both listen on the same address and port, which is why you may see an "address already in use" error when starting a server.

The address it binds to matters. Listening on 127.0.0.1 (or ::1 for IPv6) accepts connections only from the same computer. Listening on 0.0.0.0 or :: accepts them on every network interface. Many accidental exposures come from that difference.

From outside, a port tends to look one of three ways.

  • Open: something answers and accepts.
  • Closed: the machine replies that nothing is there, with a TCP reset for example.
  • Filtered: nothing comes back, usually because a firewall drops the packets.

The TCP handshake shows exactly what each answer looks like on the wire.

What a connection attempt to a port tells you
Does the connection succeed? YES A program is listening and the path allows it. The port is open. 1 NO Is it refused immediately? YES The machine answered, but nothing accepts that port or a rule rejects it. 2 NO Silence until timeout A firewall may be dropping packets, or the host or route is down. Does the connection succeed? 1 IF YES A program is listening and the path allows it. The port is open. NO Is it refused immediately? 2 IF YES The machine answered, but nothing accepts that port or a rule rejects it. NO Silence until timeout A firewall may be dropping packets, or the host or route is down.

Sockets: how programs use ports

Programmers meet ports through the socket, the operating system's handle for network communication. A server program creates a socket, binds it to an address and port, and asks to listen. Each time a client connects, the operating system hands the program a new socket for that particular conversation, while the original keeps listening for more.

A client does less. It creates a socket and asks to connect to a destination address and port. The operating system quietly assigns the source address and an ephemeral port. When the conversation ends, that temporary number eventually returns to the pool.

You can try this safely on your own machine. If Python is installed, this command serves the current folder to your computer only:

python -m http.server 8000 --bind 127.0.0.1

On some systems the command is python3. Open http://127.0.0.1:8000/ in a browser, then run one of the listing commands below in another window and you'll find port 8000. Press Ctrl+C to stop it. Run it from a folder containing nothing private, and keep the --bind option so other machines can't reach it.

A very busy client can run short of ephemeral ports toward a single destination, because each live or recently closed connection holds one. Reusing connections is the usual remedy, and it's one reason web software keeps them open for multiple requests.

Seeing what your computer is listening on

On Windows, in PowerShell:

Get-NetTCPConnection -State Listen | Sort-Object LocalPort

Each row includes an OwningProcess number, which you can look up:

Get-Process -Id 1234

Replace 1234 with the number you found. In the classic command prompt, netstat -ano shows similar information.

On Linux:

sudo ss -tulpn

That lists TCP and UDP listeners with numeric ports and the owning processes. On macOS:

sudo lsof -nP -iTCP -sTCP:LISTEN

Don't be alarmed by a long list. Operating systems run many services, and most are bound locally or blocked by the built-in firewall. For anything unfamiliar, identify the program before disabling it.

Ports in cloud and hosted services

If you run a server with a hosting or cloud provider, there are usually two gates to pass: the provider's network rules, often called security groups or a cloud firewall, and the firewall on the server itself. Both must allow a port before outsiders can reach it. When a new service works locally but not from your laptop, check both. Open only the ports the public needs, typically 80 and 443 for a website, and limit administrative ports to addresses you trust.

Ports and your home router

Your home devices usually share one public address. The router uses port numbers to keep their conversations apart, translating between inside and outside, as explained in how many devices share one address.

Outgoing connections work automatically. Unsolicited incoming ones don't, because the router doesn't know which device should receive them. Port forwarding creates that rule: traffic arriving on a chosen port goes to a chosen device. It also exposes that device to anyone on the internet who tries the port, so read how to forward ports and when not to first. Some providers place customers behind a second layer of translation, where forwarding on your own router isn't enough.

Security habits

Every listening service is a door that must be kept sound. Practical rules:

  1. Run only what you need. Turn off services you don't use.
  2. Keep listeners private where possible, bound to the local machine or local network.
  3. Use the host firewall and allow incoming traffic deliberately.
  4. Don't publish remote administration such as Remote Desktop directly to the internet. Use a VPN or a gateway with strong authentication.
  5. Patch exposed software promptly.
  6. Don't rely on odd port numbers. Moving a service reduces automated noise in logs, but scanners can find it, so it isn't protection.

You may also hear of port scanning, which is trying many ports to see which answer. Administrators use it to audit their own systems. Scanning systems you don't own or lack permission to test can break laws or terms of service; see port scanning and when it is legal.

Troubleshooting a port problem

When an application can't connect, check in this order.

  1. Is the server program running?
  2. Is it listening on the expected port and address, according to the commands above?
  3. Does a connection from the same machine work?
  4. Does it work from another device on the same network? If not, suspect the host firewall.
  5. Does it fail only from outside? Look at the router, cloud security rules or your provider.

From Windows, Test-NetConnection 192.0.2.10 -Port 443 tests a TCP port; on macOS or Linux, nc -vz 192.0.2.10 443 does where netcat is installed. Substitute your own server's address. UDP is harder to test, since silence can mean either success or failure, so use the application's own diagnostics.

Common questions

Can I choose any port for my own program?

Pick a number above 1023 that isn't already used by something you run, and check the IANA registry to avoid well-known assignments. Make it configurable so someone else can change it.

Are ports the same for IPv4 and IPv6?

Yes. Port numbers belong to TCP and UDP, which work over both. A firewall may need separate rules for each address family.

What is port 0?

It's reserved. Programs often pass 0 to the operating system to mean "choose any free port for me."

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in Internet Basics & History →

Latest news on this topic