Network Ports and Common Protocols
Explain how TCP, UDP and port numbers get traffic to the right program, know the ports support work runs into, pick secure protocols, and test a port on Windows and Mac.
Table of contents
An IP address gets traffic to the right device. A port number gets it to the right program on that device. A file server can answer ping all day while its file-sharing service refuses every connection, and the only way to see that is to test the port. Firewalls also filter by port, so many "it works at the office but not at home" tickets come down to one blocked port. Port numbers here come from IANA's Service Name and Transport Protocol Port Number Registry, checked in November 2026. Commands were checked on Windows 11, version 26H2, and macOS 27 (Golden Gate).
What You Will Be Able to Do
- Explain the difference between TCP and UDP, and which services use each.
- Recognize the port numbers support work runs into most.
- Choose the secure version of an older protocol.
- Test whether a port is reachable from Windows or a Mac, and read a failure.
- See which programs are listening on a computer.
How Ports Work
A port is a number from 0 to 65535 that marks one end of a conversation on a device. A server program listens on a known port, such as a secure web server on 443. A client picks a temporary port of its own, called an ephemeral port, for each connection.
Here is a worked example. A laptop at 10.0.5.21 opens a secure website at 203.0.113.20. The connection runs from 10.0.5.21 port 51544 to 203.0.113.20 port 443. A second tab uses another temporary port, such as 51545, so the replies never get mixed up. An address and port together are called a socket.
IANA divides the numbers into three ranges, set out in RFC 6335:
| Range | Name | Used for |
|---|---|---|
| 0 to 1023 | System ports | Core services, such as web and DNS |
| 1024 to 49151 | User ports | Registered apps, such as RDP on 3389 |
| 49152 to 65535 | Dynamic ports | Never assigned, temporary use |
Windows and macOS both pick their temporary ports from 49152 to 65535 by default. A port number is a convention, not a lock. A program can listen on any port, so a web server on 8443 is still a web server.
TCP and UDP
Most services ride on one of two transport protocols.
| TCP | UDP | |
|---|---|---|
| Setup | A handshake first | None, it just sends |
| Delivery | Confirms, re-sends, keeps order | No confirming or re-sending |
| Overhead | More | Less |
| Used by | Web, email, file sharing, remote desktop | DNS lookups, DHCP, time sync, calls |
The TCP handshake has three steps: SYN ("can we talk?"), SYN-ACK ("yes, can we?") and ACK ("yes"). If the far end never answers the first step, the connection times out.
UDP suits traffic where a late packet is worthless, such as a voice call, or where a lost question can simply be asked again, such as a DNS lookup. Some services use both. DNS uses UDP for most lookups and TCP for large answers. Newer web traffic, HTTP/3, runs over UDP port 443, while older HTTPS uses TCP 443.
The Ports Support Work Runs Into
| Port | Service | Transport | Used for |
|---|---|---|---|
| 20, 21 | FTP | TCP | File transfer, unencrypted |
| 22 | SSH, SFTP | TCP | Secure command line and file transfer |
| 23 | Telnet | TCP | Old command line, unencrypted |
| 25 | SMTP | TCP | Mail between mail servers |
| 53 | DNS | UDP, TCP | Name lookups |
| 67, 68 | DHCP | UDP | Handing out addresses |
| 80 | HTTP | TCP | Web, unencrypted |
| 88 | Kerberos | TCP, UDP | Domain sign-in |
| 110 | POP3 | TCP | Mail download, unencrypted |
| 123 | NTP | UDP | Clock sync |
| 137 to 139 | NetBIOS | UDP, TCP | Old Windows naming and sharing |
| 143 | IMAP | TCP | Mail access, unencrypted |
| 161, 162 | SNMP | UDP | Device monitoring and alerts |
| 389 | LDAP | TCP, UDP | Directory lookups |
| 443 | HTTPS | TCP, UDP | Secure web and most cloud apps |
| 445 | SMB | TCP | Windows file and printer sharing |
| 3389 | RDP | TCP, UDP | Remote Desktop |
IANA's registry lists some of these under older names, such as microsoft-ds for 445 and ms-wbt-server for 3389. Network printers add their own ports, most often 9100 for raw printing and 631 for IPP.
Email Ports
| Job | Port | Encryption |
|---|---|---|
| App sends mail to its server | 587 | Upgrades after connecting (STARTTLS) |
| App sends mail to its server | 465 | Encrypted from the start |
| Read mail with IMAP | 993 | Encrypted from the start |
| Read mail with POP3 | 995 | Encrypted from the start |
| Server to server | 25 | Not for user apps |
Port 587 is the standard port for sending mail from an app or device (RFC 6409), and RFC 8314 made 465 the encrypted-from-the-start option. Many internet providers block outbound port 25 from customer connections to stop spam. A copier, scanner or business app set to send on port 25 often fails with no clear error, so check its port first.
Secure Versions of Old Protocols
Plain text, or unencrypted, means anyone who can capture the traffic, such as on public Wi-Fi, can read it, password included.
| Old protocol | Problem | Use instead |
|---|---|---|
| Telnet (23) | Password in plain text | SSH (22) |
| FTP (20, 21) | Password and files in plain text | SFTP (22) or FTPS |
| HTTP (80) | Readable on the path | HTTPS (443) |
| POP3 (110), IMAP (143) | Mail and password readable | POP3 (995), IMAP (993) |
| LDAP (389) | Directory data readable | LDAPS (636) |
What the Main Protocols Do
- HTTPS carries web pages and most cloud apps, including Microsoft 365 and Google Workspace. The S means the connection is encrypted with TLS.
- SMB carries mapped drives and shared folders on Windows networks. The old version, SMBv1, is unsafe and should be turned off. CISA advises blocking port 445 at the internet edge, so a mapped drive that fails from home without the company VPN is usually working as designed.
- RDP carries Windows Remote Desktop. CISA advises against exposing it to the internet. People who need it from outside come in through the company's VPN or remote access gateway.
- SSH gives an encrypted command line to network gear, Linux servers and Macs.
- NTP keeps clocks in sync. On an Active Directory domain, Kerberos sign-in fails when a computer's clock is off by more than the allowed limit, which is 5 minutes by default. A wrong clock can cause sign-in errors that look like a password problem.
- LDAP lets apps look up users and groups in a directory such as Active Directory. LDAPS on 636 is the encrypted form.
- SNMP lets monitoring tools read the status of printers, switches and battery backups on 161. Devices send alerts, called traps, on 162.
Firewalls and Ports
A firewall decides which traffic may pass, mostly by address, port and protocol.
- A host firewall runs on the computer. Windows Firewall is on by default. It blocks incoming traffic that matches no rule, allows outgoing traffic, and keeps separate rules for domain, private and public networks. The Mac firewall, under System Settings > Network > Firewall, allows or blocks incoming connections by app rather than by port.
- A network firewall sits between networks, such as the office and the internet. Its rules belong to the network or security team.
A port is reachable only when a program is listening on it and every firewall in between allows it. Port forwarding is a router or firewall rule that sends traffic arriving at the public address on one port to an inside device, which opens that device to the internet.
Warning: Do not open a port, turn off a firewall, or add a rule or port forward to "test" something without approval from the team that owns it. Automated scans find exposed services such as RDP and SMB quickly, and they are a common way attackers get in.
Testing a Port
When a server answers ping but an app will not connect, test the port the app uses.
Windows, in PowerShell:
Test-NetConnection files01 -Port 445
The last line answers the question. TcpTestSucceeded : True means a program answered on that port. False means it did not.
Mac, in Terminal:
nc -vz -G 5 files01 445
The -z option only checks for a listener without sending data, and -G 5 gives up after 5 seconds. Unlike Test-NetConnection, which only reports True or False, nc tells you how it failed:
| Result | What happened | Likely cause |
|---|---|---|
| succeeded | A program answered | The port is open. Look at the app or account |
| Connection refused | The device said nothing is there | Service stopped, or wrong port |
| Operation timed out | No answer at all | Firewall dropping it, or device unreachable |
Both tools test TCP only. UDP has no handshake, so a UDP check cannot reliably prove a port is open. For a UDP service, test the service itself, such as nslookup for DNS.
Test only systems you support, and only the ports your ticket needs. Scanning ranges of ports or addresses looks like an attack, and many employers forbid it without written approval.
Seeing What Is Listening
- Windows:
netstat -anolists connections and listening ports with the process ID (PID) of the program behind each. Find the PID on the Details page of Task Manager. Adding-b, as innetstat -anob, shows the program name but needs an administrator prompt. In PowerShell,Get-NetTCPConnection -State Listenlists the same ports. - Mac:
lsof -nP -iTCP -sTCP:LISTENlists listening TCP ports and the program for each. Addsudoin front to see programs that belong to other users.
A Windows line such as TCP 0.0.0.0:3389 0.0.0.0:0 LISTENING 1180 means process 1180 is listening for Remote Desktop on every one of this computer's addresses. Here, 0.0.0.0 means "all local addresses."
Worked Example: Scan to Email Stopped
The office copier stopped emailing scans after the company moved to a new mail provider. Its settings say server smtp.example.com, port 25, no sign-in.
- From a PC on the same network,
Test-NetConnection smtp.example.com -Port 25returns False. Test-NetConnection smtp.example.com -Port 587returns True.- Port 25 is blocked on the way out, which is common. The provider expects devices to submit mail on 587 with a sign-in.
- The copier needs the provider's submission settings and an account to send from, and the mail administrator controls both.
- The ticket note reads: "Copier scan to email failing. Port 25 to smtp.example.com blocked, 587 reachable. Needs SMTP submission settings and a sending account from the mail admin."
Worked Example: Mapped Drive From Home
A user working from home can open email and the company's cloud apps, but not the S: drive on files01.
Test-NetConnection files01 -Port 445fails to resolve the name, so the laptop cannot even find the server.- The VPN is not connected. The user thought it was only for the old timesheet app.
- After the VPN connects, the same test returns True, and the drive opens.
SMB is meant to stay inside the company network. Cloud apps work over HTTPS from anywhere, but file shares need the VPN.
Common Mistakes
| Mistake | What it costs |
|---|---|
| Stopping at "ping works" | A stopped or blocked service goes unfound |
| Opening a firewall port to test | A door left open to the internet |
| Reading "Connection refused" as a firewall block | Chasing the firewall while the service is down |
| Sending device mail on port 25 | Mail that fails with no clear error |
| Telnet or FTP with a password | Passwords readable on the network |
| Trusting a UDP port check | Wrong answers either way |
Check Your Understanding
1. A server answers ping, but users cannot open its shared folders. Test-NetConnection to port 445 returns False. What next?
The server is up, but SMB is not answering. The file-sharing service may be stopped, or a firewall may be blocking 445. Escalate to the server team with both results.
2. On a Mac, nc to one port on a server says "Connection refused," and to another says "Operation timed out." What is the difference?
Refused means the server answered, but nothing listens on that port. Timed out means nothing answered at all, which usually means a firewall dropped the traffic.
3. On a sales laptop that should never accept remote connections, netstat -ano shows TCP 0.0.0.0:3389 0.0.0.0:0 LISTENING. What does that mean, and what do you do?
Remote Desktop is turned on and listening on all of the laptop's addresses. Check with your team whether it was approved, and if not, report it so it can be turned off. Do not just leave it running.
4. A user's sign-ins fail with odd errors, and their PC clock is 11 minutes off. Which protocol do you think about?
NTP on UDP 123. The clock is not syncing, and Kerberos rejects sign-ins when the clock is off by more than the limit, 5 minutes by default.
Key Takeaways
- An address finds the device. A port finds the program.
- TCP confirms and re-sends. UDP just sends, which suits DNS, DHCP, time sync and calls.
- Know the core ports: 22, 25, 53, 67 and 68, 80, 443, 445, 587, 993 and 3389.
- Choose the encrypted version: SSH, HTTPS, IMAP on 993, POP3 on 995, LDAPS and SFTP.
- When ping works and the app does not, test the port, and read refused versus timed out.
- Never open ports or expose RDP or SMB to the internet without the owner's approval.