Why the 65,536 TCP Connection Myth Is Wrong: The Real Limits Explained
The common belief that a machine can only handle 65,536 TCP connections is a misconception; in theory and practice a server or client can manage far more connections, depending on IP, port, and system limits.
The statement "Because a TCP port number is a 16‑bit unsigned integer with a maximum of 65535, a server can support at most 65536 TCP socket connections" is a classic misunderstanding, even seasoned network programmers often hold this false conclusion.
Theory
A TCP connection is uniquely identified by a four‑tuple {local_ip, local_port, remote_ip, remote_port}. For IPv4 the system can theoretically manage 2^(32+16+32+16) = 2^96 connections.
Since a typical server has a single local_ip, it can manage 2^(16+32+16) connections. A service (process, e.g., Nginx) usually listens on one local_port, so a single service can handle 2^(32+16) connections. If a client connects to a specific server endpoint (fixed local_ip, local_port, remote_ip), only 2^16 = 65536 connections are possible, which is the source of the myth.
If we consider protocols beyond TCP, a five‑tuple (adding protocol number) is used.
Practice
A server binds an ip:port and accepts connections; all accepted connections share the same local address.
Extended Content
When a client initiates multiple connections to the same TCP endpoint (ip:port), each connection must use a different local TCP endpoint. If the client has only one IP, it varies the local port, typically in the range 32768‑61000 on *nix systems, viewable with:
[[email protected] ~]# cat /proc/sys/net/ipv4/ip_local_port_range
32768 61000Thus a client can open roughly 30,000 connections to the same server endpoint.
A TCP client can reuse the same local ip:port to connect to different servers by setting the SO_REUSEADDR socket option before bind.
The system's maximum number of open file descriptors (including sockets) is:
[[email protected] ~]# cat /proc/sys/fs/file-max
580382The maximum file descriptors a single process can open is:
[[email protected] ~]# ulimit -n
1024Conclusion
Whether on the server or client side, believing that "a machine can establish at most 65,536 TCP connections" has no basis; theoretically the limit is far higher.
Additionally, on the client side the operating system automatically decides whether to reuse local ports based on different remote ip:port pairs.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
