← Bitcoin Encyclopedia

HTLC (Hash Time-Locked Contract)

🌿 Intermediate

💡 The Plain-English Definition

An HTLC — Hash Time-Locked Contract — is the cryptographic mechanism that makes trustless Lightning Network payments possible. It’s a conditional payment that completes only if the recipient reveals a secret within a time limit, or automatically refunds if they don’t.

🤔 But Why Though?

Lightning payments don’t travel directly from sender to recipient — they hop through a chain of intermediate nodes (computers running Lightning Network software). This creates a problem: how does each intermediate node in the chain forward a payment without risk of losing their funds? And how does the sender know the payment reached the recipient before funds are actually transferred?

HTLCs solve this with two simultaneous locks. The hash lock: the payment is locked behind a cryptographic secret — a random number that, when hashed (processed through a one-way mathematical function), produces a specific hash value. Only whoever knows the original secret can claim the payment. The time lock: if the secret is not revealed within a certain time window, the payment automatically refunds to the sender. No trust required — the contract executes by mathematics, not by anyone’s good faith.

The mechanism works like a chain. The recipient generates a secret and shares only its hash with the sender. The sender creates an HTLC locked to that hash, with a payment to the first intermediate node. Each intermediate node creates their own HTLC to the next, locked to the same hash, with slightly shorter time windows. When the payment reaches the recipient, they reveal the secret to claim their funds. The secret propagates backwards through the chain — each intermediate node uses it to claim their payment from the previous node. The entire chain either completes or unwinds — there’s no scenario where funds are lost in the middle. This atomicity is what makes multi-hop Lightning payments trustless: intermediate nodes can’t steal funds, and the sender can’t claim a payment failed when it didn’t.

🌍 The Real-World Analogy

Think of a locked relay race where each runner holds a sealed box that can only be opened with a specific key. The last runner — the recipient — holds the master key. They open their box and take what’s inside. Opening their box reveals the key, which the second-to-last runner uses to open their box, and so on back down the line. Each runner either gets paid (because the key was revealed) or gets their box back (because the time limit expired before the key reached them). Nobody in the middle can steal, and nobody can claim they passed the box when they didn’t.

⚡ So What?

You don’t need to understand HTLC mechanics to use Lightning — your wallet handles it invisibly. Understanding HTLCs matters for grasping why Lightning can be trustless despite involving intermediate parties: the cryptographic locks remove the need to trust any hop in the route. It also explains why Lightning payments are “atomic” — they either succeed completely or fail completely, with no funds lost in transit.

Part of The Bitcoin Encyclopedia 167 terms, plain English, no jargon.