Socket Count Calculator
Total open sockets across TCP established, TIME_WAIT, UDP and Unix domain sockets.
Inputs
Total Open Sockets
630
TCP Sockets (established + time_wait)
500
TIME_WAIT Share of Total
28.6%
Step by step
Values used
TCP ESTABLISHED (ss -t state established | wc -l) = 320; TCP TIME_WAIT = 180; UDP Sockets = 40; Unix Domain Sockets = 90
Total socket count
total = tcp_established + tcp_time_wait + udp + unix
Total Open Sockets
= 630
TCP Sockets (established + time_wait)
= 500
TIME_WAIT Share of Total
= 28.6
How it works
A system's total socket footprint spans several distinct kernel-tracked states and families: actively transferring TCP connections (ESTABLISHED), recently closed TCP connections still holding their port reserved (TIME_WAIT), connectionless UDP sockets, and local-only Unix domain sockets used for IPC. Summing these gives the total socket-table pressure a host is under, which matters for both file-descriptor budgeting and kernel memory (each socket carries buffer overhead) — a high TIME_WAIT share in particular often signals a high connection-churn workload that could benefit from connection reuse or tuned tcp_tw_reuse.
Formula
Total socket count
total = tcp_established + tcp_time_wait + udp + unix
- C_{est}
- TCP ESTABLISHED
- C_{tw}
- TCP TIME_WAIT
- U
- UDP sockets
- X
- Unix domain sockets
Frequently Asked Questions
How do I get these counts on a live system?
`ss -tan state established | wc -l`, `ss -tan state time-wait | wc -l`, `ss -uan | wc -l`, and `ss -xan | wc -l` give established TCP, TIME_WAIT TCP, UDP, and Unix socket counts respectively (subtract 1 from each for the header line if using `ss` without `-H`).
Why does a high TIME_WAIT count matter?
Each TIME_WAIT socket holds a local port tied up for 2×MSL (commonly ~60s on Linux) after close, and under very high connection churn this can exhaust the ephemeral port range or add measurable kernel memory overhead — tunable via `net.ipv4.tcp_tw_reuse` and shortened FIN timeouts, though outright disabling TIME_WAIT is not recommended as it protects against delayed duplicate segments.
Do Unix domain sockets count against the same limits as TCP/UDP sockets?
Yes — all socket types share the same per-process file descriptor budget (ulimit -n) and contribute to overall kernel socket-buffer memory, even though Unix domain sockets never touch the network stack or consume ephemeral ports.