What is Keep Alive?
Updated: Oct 27

Keep Alive is a general name for mechanisms that help manage an existing connection while it is quiet. Depending on the protocol, it can mean sending small checks to look for a responsive peer or retaining a connection so later requests can reuse it. These are related aims, but they are not the same mechanism.
A keep-alive exchange does not create bandwidth, repair a broken access line or guarantee that an application has completed its work. Its meaning depends on which layer sends it, what receives it and what the software does when the expected response is missing.
For a remote worker or a business application, the practical starting point is therefore to identify the specific feature. TCP keep-alives, HTTP connection reuse, SSH server-alive messages and WebSocket Ping/Pong exchanges operate under different rules. A setting called “keep alive” cannot safely be interpreted without that context.
Two meanings behind a familiar name
One meaning is liveness checking. Software sends a small probe or heartbeat and looks for an expected response. This can provide evidence that a particular peer and communication path remain responsive, subject to the mechanism’s scope.
The other meaning is connection reuse. Instead of closing a connection after one exchange, the software makes it available for subsequent exchanges. That can avoid repeatedly establishing a new connection, while still allowing idle limits and normal closure.
Our Persistent Connection article explains the broader idea of using an established connection for more than one exchange. Keeping that connection available and actively testing its responsiveness are separate design choices.
Mechanism | Main role |
TCP keep-alive | Probe an idle TCP peer |
HTTP persistence | Reuse a connection |
SSH server-alive | Check through the SSH channel |
WebSocket Ping/Pong | Exchange control frames |
Application heartbeat | Check an application-defined peer |
A product can use more than one of these. For example, an encrypted application connection can sit over TCP while also carrying its own messages. Changing one layer’s timer does not necessarily alter the others.
What an idle connection can hide
An established connection is a relationship recorded by software at its endpoints. A quiet interval does not continuously prove that the peer remains reachable. A device can lose power, a path can change or network state can expire while neither application is sending useful data.
The next attempt to communicate may reveal the problem. A liveness mechanism can instead provide a controlled way to investigate during a quiet period. The response still needs to be interpreted according to the protocol and the policy that uses it.
There is also a difference between a clean closure and silence. If a peer explicitly closes a connection, the local software may learn that promptly. If communication disappears without a closing exchange, software needs other evidence or a timeout before deciding how to proceed.
A missing response is not always proof that the remote computer has failed. The path might be disrupted, a response might be lost or software might be delayed. Good failure handling reports the evidence it has rather than claiming more certainty than the mechanism provides.
A conceptual liveness-check sequence
The details vary, but a heartbeat-based design commonly has the following stages. This is a general explanation rather than the exact state machine of every protocol.
The software establishes the connection and completes any required authentication.
The connection becomes quiet under the mechanism’s definition of inactivity.
A timer or supported scheduling rule triggers a small check.
The peer responds in the expected form, providing evidence of responsiveness at that layer.
If the response is absent, the software applies its documented waiting and missed-check policy.
Once that policy declares the connection unusable, a separate recovery process decides whether and how to reconnect.
The recovery step matters. A checker can discover a problem without possessing the application state, permissions or retry rules needed to recover from it. Detecting an unresponsive peer is only part of a complete remote-work design.
TCP keep-alives check the transport peer
The TCP specification, RFC 9293, describes probes for an idle TCP connection. Where this optional facility is implemented, applications must be able to enable or disable it per connection, and it must default to off.
The standard also requires a configurable idle interval whose default is no less than two hours. That is a TCP specification requirement, not a recommendation to use two hours for every application heartbeat. Software and operating-system configuration must be checked for the actual connection.
RFC 9293 explicitly rules out treating the failure of one particular probe to receive a response as sufficient proof of a dead connection. A single missed response can have other explanations.
A TCP response establishes limited transport-level evidence. It does not confirm that a database query is making progress, that a remote desktop is rendering correctly or that a file has been saved. Those outcomes need their own application checks.
HTTP keep-alive usually concerns reuse
HTTP/1.1 uses persistent connections by default, as explained in RFC 9112. Multiple requests and responses can use one connection, subject to the protocol’s framing and closure rules.
This is not a promise that periodic heartbeat messages are being sent. A connection can be available for reuse while no request is currently in progress. The software can still close it, and a later request may need a new connection.
Correct message handling is essential. RFC 9112 requires a client intending to reuse a connection to read the full response body. Otherwise, the next exchange cannot simply assume that all earlier response data has been dealt with.
Web-server settings can add further limits. The nginx documentation, for example, distinguishes an idle keep-alive timeout from limits on requests and connection lifetime. Those settings have a resource-management purpose and should not be mistaken for the interval between TCP probes.
Protocol versions matter too. RFC 9113 prohibits generating HTTP/2 messages containing connection-specific header fields such as Connection and Keep-Alive. Copying an HTTP/1.x header recipe into an HTTP/2 system is therefore not a general solution. Use the supported client and server controls for the actual protocol.
SSH server-alive messages use the encrypted channel
OpenSSH provides its own server-alive mechanism. The OpenSSH client manual describes ServerAliveInterval as the period without received server data after which the client requests a response through the encrypted SSH channel.
ServerAliveCountMax controls how many such messages can be sent without receiving messages back before the client disconnects under that mechanism. These are different controls from TCPKeepAlive. Check the manual for the installed software version before applying configuration advice.
The documented default ServerAliveInterval is zero, so these SSH-level messages are not sent by default. That does not mean every SSH client, managed configuration or operating system has identical effective settings.
Our SSH Session guide explains the wider connection and authentication context. A responsive SSH channel is useful evidence, but it does not establish the success of a command or preserve a process after every kind of disconnection.
WebSocket Ping and Pong are control messages
The WebSocket specification, RFC 6455, defines Ping and Pong control frames. A peer receiving a Ping must respond with a Pong unless it has already received a Close frame. A responsive Pong carries the same application data as the Ping it answers.
The specification identifies keep-alive and checking responsiveness as possible uses of Ping. It does not prescribe one universal interval that every application should use. The surrounding library and application determine their supported timing and failure behaviour.
A protocol Pong and an application-defined heartbeat message are also different things. A message with a business-specific name might check additional application logic, while a protocol control frame can be handled at another point in the software stack. Establish what actually generates the response.
Neither kind of reply should automatically be labelled “the job is healthy”. The correct claim is narrower: the component responsible for that reply responded under the conditions observed.
Worked example: interval plus reply deadline
Consider a fictional application heartbeat policy. It last receives a valid reply at time zero. It schedules checks at 30, 60 and 90 seconds, allows ten seconds for each reply, and declares the connection unresponsive only after three missed reply deadlines.
Illustrative event | Time from start |
Last valid reply | 0 s |
First check; deadline | 30 s; 40 s |
Second check; deadline | 60 s; 70 s |
Third check; deadline | 90 s; 100 s |
Third deadline missed | 100 s |
Under these deliberately stated rules, the declaration occurs at 100 seconds, not simply 30 × 3 = 90 seconds. The difference comes from the ten-second response window after the final scheduled check.
This is original illustrative arithmetic, not TCP or SSH default behaviour. Real implementations may count unanswered messages differently, reschedule after activity or include additional delays. Read the implementation’s rules instead of deriving a guaranteed detection time from an option name.
If the fictional second check receives its expected reply at 65 seconds, that reply arrives before its 70-second deadline. Under a policy that resets the missed-check count after a valid reply, the illustrated three-miss sequence no longer applies. This shows why the treatment of ordinary traffic and replies needs to be explicit.

Shorter intervals have a cost
More frequent checks can provide earlier opportunities to notice some failures. They also produce more messages and can be less tolerant of temporary delays. The right balance depends on the application, network and operational requirements.
For another original example, imagine 1,000 otherwise quiet connections. Each sends one application check every 30 seconds and receives one reply. Spread evenly over time, that gives 1,000 ÷ 30, or about 33.3 checks per second, plus about 33.3 replies: roughly 66.7 application messages per second.
At a 15-second interval, the same model gives roughly 133.3 messages per second. Halving the interval doubles the modelled message rate. It does not establish that a real application detects every fault twice as quickly.
These are message counts, not network packet counts or a bitrate calculation. They exclude protocol headers, acknowledgements, encryption, retransmissions and ordinary traffic. Real schedules can also align and create bursts instead of the evenly spread rate assumed here.
A reply is not a complete health check
Think about where the response is produced. A network stack may respond while an application is stuck. An application’s heartbeat handler may respond while a separate worker or database is failing. A proxy can be responsive while a service beyond it is unavailable.
This does not make a lightweight check useless. It defines the evidence it supplies. Combine that evidence with the actual task outcome when diagnosing a problem.
For example, a fictional reporting service may answer heartbeats while a particular report remains queued. The heartbeat confirms that its responder is reachable; a separate status record establishes whether the report is pending, running, complete or failed. Those observations answer different questions.
Avoid turning a heartbeat into an expensive full application transaction unless that is the intended design. A frequent check that performs substantial work can add load to the very service it is meant to observe. Choose a scope that fits the requirement and record the limits of the result.
Keep-alive does not override session policy
An account can expire, permissions can change and a service can enforce an inactivity rule independently of transport responsiveness. Background network messages need not count as meaningful user activity under an application’s security policy.
Our Session Timeout article distinguishes the end of a session from other connection behaviours. A connection that still answers a probe does not prove that the user remains authorised for the next action.
Treat authentication renewal and access checks through the application’s supported flow. Do not use synthetic activity to defeat an organisation’s intended expiry policy. A usable connection and a valid session are separate prerequisites for many remote tasks.
Likewise, keep-alive cannot bring back unsaved work or recreate a remote process that has ended. Persistence, checkpointing and reconnection need appropriate application support. The small message alone does not provide those features.
What about routers, firewalls and idle limits?
Some devices and services maintain state for a connection and apply idle limits. Traffic may affect that state, but the details depend on the device, protocol, direction and policy. Do not assume that any tiny message refreshes every timer along the path.
A home worker may have local WiFi, a router, provider infrastructure, a VPN gateway and a remote service involved. A branch application may cross further proxies or load balancers. The apparent “connection timeout” could originate at several boundaries.
Where administrators have authorised visibility, compare the recorded closure times and relevant component settings. Identify whether the idle period is measured from the last sent message, last received message or a particular application event. A setting at the wrong boundary may have no useful effect.
A sleeping laptop or a powered-off router also cannot keep sending checks normally. Keep-alive is communication over an available path, not an alternative source of power or connectivity. Recovery after sleep or an address change needs separate testing.
Five questions before changing a timer
Which protocol layer owns the keep-alive feature being changed?
What event starts or resets its inactivity timer?
What response is expected, and how are missed responses counted?
What resource and message cost will the chosen interval create?
What should the application do after the connection is declared unusable?
Include both endpoints and relevant intermediaries in the discussion. A client-only change can conflict with a server policy or leave the application’s actual failure condition untouched. Prefer the supported, narrowly scoped configuration for the intended service.
Troubleshoot in six stages
Record the application, endpoint, protocol, symptom and approximate time before the problem appears.
Distinguish a quiet connection that closes from an active transfer that stalls or fails.
Identify the effective keep-alive, idle-timeout and session-expiry settings at the relevant layers.
Observe authorised logs or diagnostics to establish whether checks are sent and expected replies return.
Compare the observations with the documented counting, deadline and reset rules.
Make one justified change and retest both normal idle behaviour and the application’s supported recovery path.
Protect useful work before testing failures. A test that confirms a checker can detect a disconnected path should also confirm what the user sees afterwards. Clear status and safe recovery matter more than making a socket appear open indefinitely.
Frequently asked questions
Will Keep Alive stop every disconnection?
No. It can support particular idle-connection or responsiveness behaviour. It cannot prevent physical outages, endpoint shutdown, deliberate closure or every application timeout.
Is HTTP keep-alive the same as TCP keep-alive?
No. HTTP persistence concerns reusing a connection for multiple exchanges. TCP keep-alives probe an idle transport connection. A system may use both, but their controls and meanings differ.
Does a successful heartbeat prove the application is working?
Only within the check’s scope. It proves that the relevant responder produced the expected reply. A separate query, worker or business operation may still be failing.
What is the best keep-alive interval?
There is no universal value. Use the implementation’s documentation, the application’s failure-detection requirement and the actual path’s policies. Test the trade-off between responsiveness, transient delays and message cost.
Does Keep Alive automatically reconnect?
Not necessarily. Failure detection and reconnection are separate behaviours. The application needs a supported recovery process that handles authentication, state and any uncertain operation outcomes.
The key takeaway
Keep Alive can mean reusing a connection or checking whether a particular peer still responds. Identify the layer, timer, reply and failure policy before changing it. Verify the useful application outcome separately, and treat reconnection, saved work and session authorisation as their own requirements.

