eli5: why so many ports?

143 views

“TCP also introduces a concept of a port: each connection has two ports, one for both sides. A port is an integer between 0 and 65535. A server typically waits for a new connection at a well-known port. Default ports for widely-used protocols are well-established and are typically small numbers, for example, HTTP uses port 80. A client also needs its own port. These ports are typically large numbers selected automatically by an operating system, based on what ports are available.”

Why is there a need for so many ports if there is just a client and a server? If there were multiple clients I assume the port number would need to be significantly big, but 65535 is relatively small.

In: 7

6 Answers

Anonymous 0 Comments

To directly address the question of 65535 seeming very small:

In theory a server could only have a single TCP port available and still work just fine even if millions of devices connect to it simultaneously. This is because each connection, aka Session, is uniquely identified by 4 numbers. Client IP, Client TCP Port, Server IP and Server TCP Port. Obviously the Server IP and Port will be the same for every connection/session, but as long as the Client IP or Port change, it’s easy to keep track of who’s who.

If a client needs multiple sessions to the same server & port, it just picks one if it’s unused ports for each new session it needs. That’s why you can open multiple browser tabs to the same website, at the same time but all with different pages open, and both your phone and the server know what info belongs to what session/tab. (It might be easier to think of a small site with 1 server here – big companies have multiple servers, sites, load balancers, etc, but that is to do with physical limitations, not the fact that only 1 TCP port is being used)

So in fact 65535 ports is 65534 more than you need on a server for each service.

You are viewing 1 out of 6 answers, click here to view all answers.