An HTLC puts two separate locks on one secret. The hash lock permits a claim only from someone holding the preimage behind the hash. The time lock hands the funds back to the sender if no claim lands before a given block height. Together they carve out a window in which a cross-chain swap can settle without either side having to trust the other.
Why that works, where the guarantees hold, and where they stop matter for anyone assessing an HTLC-based protocol fairly. This piece walks the structure from lock to reveal to timeout.
Two Locks, One Secret
A hash runs one way. Supply the preimage and the hash comes out fast. Hold only the hash and reversing it to find the preimage is infeasible.
Party A, the initiator, picks a random secret, hashes it, and builds an HTLC on their chain locking funds against that hash. The HTLC offers two exits: the correct preimage before the deadline, or the deadline passing and the funds returning to Party A.
Party B checks Party A's HTLC, confirms the hash, and builds a matching HTLC on the other chain against the same hash. Party B's funds now sit under the same hash condition, but on a shorter clock. The asymmetry is deliberate.
The only route to the other side's HTLC is publishing the preimage. When Party A claims from Party B's lock, the revealed secret lands on-chain and anyone can read it. Party B uses the same preimage to claim from Party A's lock. The claim reaches both sides or it reaches neither.
Why the Timeouts Must Differ
The timeout gap carries real security weight. It is what blocks a particular kind of fraud.
Party B's clock must run out before Party A's. Equal timeouts would let Party A wait for the final moments, claim from Party B's HTLC by publishing the preimage, then move so B cannot see the reveal in time to claim from A's lock. Party A would end up holding both sides.
Putting Party B's timeout earlier hands B a window to see A's reveal and claim from A's HTLC before that lock lapses. The gap is a safety margin, and it has to absorb the worst-case propagation delay on both chains.
On Bitcoin legs the margin has to swallow Bitcoin's variable confirmation times. We normally place at least 24 hours between the two timeouts when mainnet is involved. Swaps among faster-finality chains can run a shorter margin, but the asymmetry stays.
Calibrating the Window
Timeout tuning ranks among the more practical hard parts of HTLC integration. Too short and swaps fail because a party could not get its transaction confirmed in time. Too long and capital sits locked when swaps stall.
One developer working through the SDK hit this head-on. Building a Bitcoin-to-Ethereum route, they set timeouts from documentation figures that ignored the gap between average block time and worst-case confirmation time under congestion. Party B's timeout sat too close to Party A's. In normal conditions swaps completed. Under Bitcoin congestion the margin fell below what reliable preimage propagation needs, and swaps began failing after Party B had already committed funds.
The fix was a more conservative model: worst-case block times drawn from historical congestion, not averages. No protocol avoids this. Any HTLC implementation touching Bitcoin mainnet has to plan around variable block times.
Following a Swap Through
A completed HTLC swap moves through four stages: initiation, counterparty lock, preimage reveal, and settlement.
At initiation, Party A creates the HTLC and shares the hash, never the preimage, with the matching infrastructure. The secret stays with Party A until reveal.
At counterparty lock, Party B builds its HTLC on the other chain against the same hash with an appropriate asymmetric timeout. Both sides have committed funds. Neither can claim yet. The swap is live and both are exposed to the clock.
At preimage reveal, Party A publishes the secret on-chain to claim from Party B's lock. That is the point of no return for A. Once the preimage is on-chain, Party B can read it and claim from Party A's HTLC, leaving both sides claimable at once.
At settlement, each party claims from its respective HTLC. If either misses its timeout window, the funds revert to their original holder, with loss on neither side.
The Edge of the Guarantee
HTLCs do not make cross-chain swaps risk-free, and any protocol implying otherwise is overselling. The cryptographic guarantee reaches atomicity and stops there. Counterparty discovery, rate setting, and timeout calibration are infrastructure questions outside the hash lock and time lock.
The rate gets agreed before the HTLC exists. The HTLC enforces an atomic exchange of the agreed amounts but cannot stop a party from walking away before creating its lock. Should Party B look at Party A's HTLC and decide the rate no longer suits, B can decline to create the matching lock. Party A's funds are safe and come back at timeout, yet the swap does not happen.
Nor does the HTLC address the layer where counterparties meet and rates are struck. Front-running in the mempool, where an observer catches a preimage reveal and races the intended claimant, belongs to block construction, not to the HTLC itself. That remains an active research area.
What the Construction Leaves Out
HTLCs solve one problem well: making a two-party exchange atomic across chains that cannot read each other's state. Adjacent problems stay outside them.
They cannot promise a price. They cannot promise a counterparty will show. They cannot prevent timeout failures born of congestion or bad parameters. They cannot stop a party from abandoning a swap before the second lock exists. Each of those belongs to a layer above.
Matching infrastructure, routing algorithms, and timeout tooling cover the adjacent ground. The HTLC delivers the atomic guarantee that makes those upper layers worth building. Knowing where the guarantee ends and the infrastructure begins is what lets anyone audit or integrate a cross-chain system, and judge the trust model of a protocol resting on HTLCs.