← 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, and refunds automatically if they don’t.

Routing sends your money through strangers — so how does no one steal it? Each hop is locked with the same secret and a deadline: a middleman only gets paid once they can prove they paid the next person. When the recipient reveals the secret, it unlocks every hop back up the chain; if the secret never appears, every payment refunds. Nobody in the middle can run off with it.Diagram by Bit By Bitcoin.

🤔 But Why Though?

Lightning payments don’t travel straight from sender to recipient — they hop through a chain of intermediate nodes (computers running Lightning software). That creates a problem: how does each node in the middle forward a payment without risking its own funds? And how does the sender know the payment actually reached the recipient?

HTLCs solve this with two locks at once.

The hash lock: the payment is locked behind a secret — a random number that, when hashed (run through a one-way function), produces a specific fingerprint. Only whoever knows the original secret can claim the payment.

The time lock: if the secret isn’t revealed within a set time window, the payment refunds to the sender automatically. No trust required — the contract runs on mathematics, not on anyone’s good faith.

The whole thing works like a chain. The recipient generates a secret and shares only its hash with the sender. The sender sets up an HTLC locked to that hash, paying the first node in the route. Each node in turn sets up its 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 — and the secret then travels back up the chain, each node using it to claim its payment from the one before. The entire chain either completes or unwinds; there’s no situation where funds get stuck or lost in the middle. That all-or-nothing property — atomicity — is what makes multi-hop Lightning payments trustless: a node in the middle can’t steal the funds, and the sender can’t pretend 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 only opens with a specific key. The last runner — the recipient — holds the master key. They open their box and take what’s inside. Opening it reveals the key, which the second-to-last runner uses to open theirs, and so on back down the line. Each runner either gets paid (because the key reached them) or gets their box back (because the time limit expired first). 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 them matters for seeing why Lightning can be trustless even though it runs through intermediate parties: the cryptographic locks remove any need to trust the hops along the way. It also explains why Lightning payments are “atomic” — they either succeed completely or fail completely, with no funds lost in transit.

📩 The Daily Bit · free

Get one plain-English Bitcoin email each morning.

The Daily Bit — free, two minutes, unsubscribe anytime.

The Bitcoin EncyclopediaPrefer a book? The Bitcoin Encyclopedia