What is a Port? The Visual Guide to Network Ports

Every network connection uses a port number. Learn what ports are, why they exist, and how TCP/UDP ports work with real-world analogies and hands-on commands.

Network diagram showing a computer with multiple open port doors, each labeled with a different service
📧

Get weekly IT guides

Join 5,000+ IT professionals

Subscribe Free

Your computer is having 200+ conversations right now. Your browser, Slack, Spotify, and your email client are all talking to different servers — simultaneously. How does your computer know which data belongs to which app? How does it not mix up your Spotify music with your bank login?

The answer is ports.

What is a Port?

A port is a number — just a number (0 to 65535) — that tells your operating system which application should receive a piece of network data.

Think of it as a room number inside a building:

🏨 The Hotel Analogy

Your IP address is the hotel’s street address. Everyone can find the building.

A port is the room number inside that hotel.

  • Room 80 → HTTP (the web, unencrypted)
  • Room 443 → HTTPS (the web, encrypted)
  • Room 22 → SSH (remote server login)
  • Room 53 → DNS (the internet’s phonebook)

When data arrives at your IP address, the OS reads the port number and delivers the data to the correct “room” (application).

Hotel building diagram with rooms labeled by port number: 22 SSH, 53 DNS, 80 HTTP, 443 HTTPS, 3306 MySQL
IP address = the building. Port = the room number. Each service lives in a specific room.

Why Do Ports Exist?

Without ports, your computer could only have one network conversation at a time.

Here is what happens when you load a webpage in your browser while Spotify plays in the background:

  1. Browser sends a request to google.com port 443 (HTTPS)
  2. Spotify sends a request to Spotify’s servers on port 443 (also HTTPS)
  3. Both responses come back to your IP address
  4. Your OS reads the port number on each response packet and delivers:
    • The Google response → to your browser
    • The Spotify audio data → to the Spotify app

Without ports, your browser would get Spotify’s audio and Spotify would get your Google search results. Chaos.


The 3 Port Ranges

Number line from 0 to 65535 divided into Well-Known Ports (0-1023), Registered Ports (1024-49151), and Ephemeral Ports (49152-65535)
Port numbers are divided into three ranges with different rules and uses.
RangeNumbersNameWho Uses Them
Well-Known0 – 1023System PortsMajor internet services (HTTP, SSH, DNS). Require root/admin to bind.
Registered1024 – 49151Application PortsCommon apps: MySQL (3306), Redis (6379), MongoDB (27017).
Ephemeral49152 – 65535Dynamic/PrivateAuto-assigned temporary ports for outgoing connections.
Source Port vs Destination Port

Every connection has two port numbers — one on each end.

  • Destination Port: The port the server is listening on. (e.g., 443 for HTTPS)
  • Source Port: A random ephemeral port your OS assigns to track the reply. (e.g., 54823)

When the server replies, it sends data back to: your-IP : 54823. That’s how your OS knows to give the response to your browser and not Spotify.


TCP vs UDP Ports

The same port number can exist on both TCP and UDP — they are completely separate.

ProtocolPortsBehavior
TCPTCP/80, TCP/443, TCP/22Connection-based. Handshake required. Reliable delivery.
UDPUDP/53, UDP/67, UDP/123No connection. Fire-and-forget. Faster, lower overhead.

For example:

  • DNS uses UDP/53 for normal queries (fast, tiny packets)
  • DNS uses TCP/53 for large responses or zone transfers (reliability needed)

The Most Important Ports You Must Know

🧠 Memory Rule

You don’t need to memorize all 65,535 ports. You need to know the ~20 ports that appear in 95% of real-world work.

PortProtocolTransportWhat It Is
20/21FTPTCPFile Transfer (21=control, 20=data)
22SSHTCPSecure remote login. You’ll use this every day.
25SMTPTCPEmail sending (server → server)
53DNSUDP/TCPThe internet phonebook. Every web request uses this.
67/68DHCPUDPHow your computer gets its IP address on boot.
80HTTPTCPUnencrypted web traffic.
110POP3TCPOld email retrieval (avoid)
143IMAPTCPModern email retrieval
443HTTPSTCPEncrypted web. This is ~95% of web traffic today.
587SMTP (TLS)TCPEmail sending from your email client
3306MySQLTCPMySQL/MariaDB database connections
5432PostgreSQLTCPPostgreSQL database connections
6379RedisTCPRedis cache/message broker
8080HTTP-altTCPDeveloper local servers (localhost:8080)
27017MongoDBTCPMongoDB database

What is a Socket?

A socket is the full address of one end of a network connection. It combines the IP address + port number:

Socket = IP Address + Port Number
Example: 142.250.80.46:443

When your browser connects to Google, the full “conversation” is identified by a 4-tuple:

[Your IP] : [Your ephemeral port]  ↔  [Google's IP] : 443
192.168.1.5 : 54823               ↔  142.250.80.46 : 443
Diagram showing a laptop with socket 192.168.1.5:54823 connected to Google server at 142.250.80.46:443
A socket is the full address: IP + Port. A connection is defined by the 4-tuple of both sockets.

This is why your computer can have thousands of simultaneous browser tabs open — each tab gets a unique source port, so the OS can track each conversation separately.


Hands-On: See Your Open Ports Right Now

Try This on Your Linux/macOS Terminal

The best way to understand ports is to see them on your own system.

Step 1: See all listening ports (what your computer is serving to others)

ss -tulpn

Show all TCP/UDP ports currently listening on your system

beginner
  • -t = TCP, -u = UDP, -l = listening only, -p = show process name, -n = show numbers not names
  • Look for the 'Local Address:Port' column — that's what each service is bound to
  • 0.0.0.0:80 means listening on ALL interfaces on port 80
  • 127.0.0.1:3306 means MySQL is only accessible from localhost (good security!)

Step 2: See all active connections (conversations happening right now)

ss -tn

Show all active TCP connections — who your computer is talking to right now

beginner
  • ESTABLISHED = active conversation in progress
  • TIME_WAIT = connection recently closed, waiting to expire
  • LISTEN = waiting for incoming connections on this port
  • The 'Peer Address:Port' column shows which remote server you're connected to

Step 3: See which process owns a specific port

sudo lsof -i :80

Find which process (app) is using port 80 on your system

beginner
  • Replace 80 with any port number you want to investigate
  • Useful when you get 'port already in use' errors
  • The PID column gives you the process ID — use 'kill PID' to stop it

Step 4: Check if a specific port is open on a remote server

nc -zv google.com 443

Test if port 443 is open on google.com (timeout = closed/filtered)

beginner
  • -z = scan mode (don't send data), -v = verbose output
  • Connection succeeded = port is open and reachable
  • Connection refused = port is closed
  • Timeout = firewall is blocking/dropping the connection

Hands-On Challenge

Try these steps on your own Linux or macOS machine:

  1. Run ss -tulpn → Find which port your SSH server is listening on (hint: it should be 22)
  2. Run ss -tn → Find an ESTABLISHED connection and look up the remote IP on ipinfo.io
  3. Run sudo lsof -i :8080 → Is anything using port 8080? (common dev server port)
  4. Bonus: Start a Python web server (python3 -m http.server 9999) then run ss -tulpn again. You should see port 9999 appear.

Key Takeaways

  1. A port is just a number (0-65535) that tells the OS which app gets the incoming data.
  2. IP address = the building, Port = the room number. You need both to reach the right app.
  3. Well-Known ports (0-1023) are for major services. Registered (1024-49151) for apps. Ephemeral (49152-65535) for outgoing connections.
  4. Every connection has two ports: the server’s stable listening port, and your computer’s random source port.
  5. TCP and UDP are separate — the same port number can exist on both protocols independently.
  6. ss -tulpn is your go-to command to see exactly what’s listening on your system.
You Now Know

What a port is, why they exist, how TCP/UDP ports differ, and how to inspect your own system’s open ports. You’ve moved from “ports are magic numbers” to understanding the complete address system of a network connection.

Next Steps

🧠

Test Your Knowledge

Take a quick 5-question quiz to check your understanding.

📧

Get weekly IT guides

Join 5,000+ IT professionals

Subscribe Free
Type to start searching...