What is a port number, and how is it different from an IP address?
An IP address identifies a machine on a network. A port number (0 to 65535) identifies which program on that machine should receive the data. Together they pick out one exact conversation endpoint.
Explain it simply
An IP address is like the street address of a college hostel. A port is the room number. The postman needs both, otherwise the letter reaches the building but nobody knows whom to give it to.
Example
https://example.com -> 203.0.113.7 : 443 (web server)
ssh user@203.0.113.7 -> 203.0.113.7 : 22 (SSH daemon)
same machine, same IP, different programsPort ranges: 0 to 1023 are well-known (80 HTTP, 443 HTTPS, 22 SSH, 53 DNS, 25 SMTP). 1024 to 49151 are registered, and 49152 to 65535 are mostly used as temporary ports. When your browser connects, the operating system picks a random temporary source port, such as 51734, so replies find the right tab.
Ports belong to the transport layer, so TCP port 53 and UDP port 53 are separate things.
What to say in the interview
"The IP address finds the host; the port finds the process. A port is a 16-bit number, so there are 65,536 of them. TCP and UDP each have their own port space. The pair of IP and port is what the OS uses to hand arriving data to the correct application."
Common mistakes
- Thinking a port is a physical socket on the computer.
- Forgetting that the client also uses a port, a random temporary one.