This article was translated from Japanese with AI. Read the original (日本語) · Report a translation issue

When you send or receive payments over the Lightning Network, have you ever come across a string like the one below?

lnbc20m1pvjluezsp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygspp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqsfpp3qjmp7lwpagxun9pygexvgpjdc4jdj85fr9yq20q82gphp2nflc7jtzrcazrra7wwgzxqc8u7754cdlpfrmccae92qgzqvzq2ps8pqqqqqqpqqqqq9qqqvpeuqafqxu92d8lr6fvg0r5gv0heeeqgcrqlnm6jhphu9y00rrhy4grqszsvpcgpy9qqqqqqgqqqqq7qqzq9qrsgqdfjcdk6w3ak5pca9hwfwfh63zrrz06wwfya0ydlzpgzxkn5xagsqz7x9j4jwe7yj7vaf2k9lqsdk45kts2fd0fkr28am0u4w95tt2nsq76cqw0

This is called a Lightning invoice: a payment request that contains the information needed for the transfer.

It is usually generated when the person receiving the payment presses the "Receive" button in their wallet.

This article covers the basics of invoices, breaks down the information they contain, and even shares some lesser-known trivia along the way.

Decode Lightning Network Requests - BOLT11, LNURL, and Lightning Address
Lightning Decoder is a tool for decoding Lightning Network request codes - BOLT11s, LNURL codes, and Lightning Addresses are supported.

The "Lightning Decoder" above is a site that decodes invoices. Comparing its output with the explanations in this article should make things easier to follow, so feel free to use it alongside.

Let's get into it.

What is an invoice?

An invoice is a payment request for the Lightning Network, defined in BOLT #11.

When creating one, the recipient generates a piece of secret data called the "preimage" and includes its hash (payment_hash) in the invoice. The preimage is secret information that must not be revealed to anyone until the very moment the payment completes, and using it as the key is what guarantees the atomicity of the payment.

💡
"Atomicity" means there are only two possible outcomes: everything succeeds or everything fails. In other words, a payment can't partially fail along the way with funds being skimmed off while it is being relayed.

If you want to learn more about how the preimage is involved in payments, see this article.

HodlインボイスがLNを舞台裏で支える | カストディを防ぐライトニング随一の「裏ワザ」とは
ライトニングネットワークにおけるHodlインボイスの仕組みと活用例、短時間の使用がライトニングのノンカストディアルな利用にとってポジティブな理由を解説。逆に、長時間のHodlインボイスが推奨されない理由となるデメリットも分かりやすく紹介します。

The basic structure of a Lightning invoice

An invoice consists of a human-readable part and a data part, and is encoded in Bech32. It is normally written entirely in lowercase, but when turned into a QR code it is often written in uppercase for better space efficiency.

The main components of an invoice are as follows.

Human-readable part

  • Prefix
  • Amount

Data part

  • Timestamp
  • Tagged fields (zero or more)
  • Signature

Between the human-readable part and the data part sits the digit "1". It acts as the separator defined by Bech32.

Structure of an invoice

Prefix

An invoice begins with ln, which stands for Lightning Network, followed by a dedicated identifier, modeled on the definitions in BIP173, that indicates the network, such as mainnet or testnet.

lnbc: Bitcoin Mainnet

lntb: Testnet Bitcoin

lntbs: Bitcoin Signet

lnbcrt: Bitcoin regtest

In other words, when you receive a payment on Lightning mainnet, the invoice will always start with lnbc, so it's a good idea to check.

Amount

After the prefix comes the part that represents the amount.

Normally the recipient specifies an amount when creating an invoice, but it's also possible to create one without an amount. In other words, this part can be skipped.

💡
With an amount-less invoice, the payer can set the amount themselves. This is used for things like donations, but since an invoice can only be used once, a Lightning Address is far more convenient. Perhaps for that reason, my impression is that many wallets these days don't even let you create invoices without a specified amount.

Amounts are denominated in BTC rather than satoshis (sats). To save space, they are expressed with multipliers: for example, 1 sat is written as 10n, 100 sats as 1u, and 1 msat as 10p.

Unit Multiplier In sats
m (milli) 0.001 100,000
u (micro) 0.000001 100
n (nano) 0.000000001 0.1
p (pico) 0.000000000001 0.0001
💡
Here's a bit of trivia: you can actually pay up to twice the amount stated in an invoice (depending on the wallet implementation). According to BOLT #11, the purpose is to let payers add small variations that make their payments harder to track. That said, few wallets let you change the specified amount when paying, so see if you can find one.

Timestamp

The data part begins with a 35-bit timestamp.

The timestamp is the time elapsed since 00:00 UTC on January 1, 1970, commonly known as epoch seconds (Unix time / Unix timestamp).

Since Bech32 encodes 5 bits per character, 35 ÷ 5 = 7, which means the timestamp is represented by exactly 7 alphanumeric characters.

💡
The maximum value of a 35-bit unsigned integer is \(2^{35}\)-1 = 34,359,738,367 seconds. That covers dates up to around the year 3059, so there's no need to worry about it overflowing for roughly 1,000 years.

Tagged fields

Tagged fields are data units in TLV (Type-Length-Value) format that can store information used when making the payment.

Their basic structure consists of three elements in the order type, data_length, data.

Element Size Contents
type 5 bits What kind of information it is (identifier)
data_length 10 bits Length of data
data data_length × 5 bits The actual contents

Everything is in 5-bit units because Bech32 encoding represents 5 bits per character (32 possible characters).

Currently defined tagged fields

The currently defined tagged fields are listed below. To create an invoice, p (payment_hash) and s (payment_secret) are required. In addition, exactly one of d (short description) or h (description hash) must be included.

Type characterField nameContents
ppayment_hash256-bit SHA256 payment_hash. Its preimage is revealed later in the payment process and serves as proof of payment.
spayment_secret256-bit secret. Prevents forwarding nodes from probing for the recipient.
ddescriptionA short description of the payment's purpose in UTF-8, e.g., "one cup of coffee." If this field is not set, the h tag must be used instead.
mmetadataAdditional metadata to attach to the payment.
nnode_idCan contain the 33-byte public key of the recipient's node.
hhashIf the description doesn't fit in the d field, the hash of a longer description can be included here. How the full description is communicated is not specified here.
xexpiryExpiry time in seconds. The default is 3600 seconds.
ccltvmin_final_cltv_expiry_delta for the last HTLC in the route. The default is usually 18.
ffallbackCan contain an on-chain fallback address in case the Lightning payment fails for some reason.
rroute hintsOne or more entries containing additional routing information for private routes. Each route hint contains:
• pubkey (264 bits)
• short_channel_id (64 bits)
• fee_base_msat (32 bits, big-endian)
• fee_proportional_millionths (32 bits, big-endian)
• cltv_expiry_delta (16 bits, big-endian)
9featuresOne or more 5-bit values indicating the features supported or required to receive this payment.

The advantage of the Type-Length-Value format is that when a reader encounters a type it doesn't recognize, it can look at data_length and know it can safely skip that many bits (the length of the data). This means new fields (types) can be added in the future without breaking older implementations.

Signature

At the end of the invoice is a 520-bit digital signature made with the recipient's private key. The signature is created over the SHA256 hash of the human-readable part plus the data part (excluding the signature), so if even a single character of the invoice is tampered with, the signature will no longer match.

Since Bech32 uses 5 bits per character, 520 ÷ 5 = 104 characters, which appear as the signature right at the end of the invoice (just before the checksum).

💡
The checksum (for error detection) follows the signature as 6 characters.

Summary

A Lightning invoice is a payment request defined in BOLT #11 and encoded in Bech32 format.

It is broadly divided into two parts, the human-readable part (prefix + amount) and the data part (timestamp + tagged fields + signature), separated by 1.

  • Prefix: Indicates the network, e.g., lnbc.
  • Amount: Expresses a BTC-denominated amount concisely using the m/u/n/p multipliers. Can be omitted.
  • Timestamp: Records the time of creation in epoch seconds (35 bits).
  • Tagged fields: Store variable supplementary information in TLV format, such as p (payment_hash) and d (description).
  • Signature: A 520-bit digital signature made with the recipient's private key that detects any tampering with the contents.

Thanks to these mechanisms, a Lightning invoice can convey who to pay, how much, for what, and by when in a single compact, tamper-resistant string.