Invoice Encoding

The standard string format for a Lightning payment request, with amount, payment hash and route hints inside.

Basically

Invoice encoding is a standard way to turn a Lightning payment request into a string you can copy or scan. The string carries the payment details.

Key Takeaways

  • Lightning invoices use Bech32 to pack payment details into one human-readable string. The prefix identifies the network and amount, tagged fields carry the payment hash, description, expiry and routing hints, and a cryptographic signature completes the invoice.
  • BOLT 11 is the dominant invoice standard today. Its single-use design and requirement for the receiver to be online to generate invoices led to BOLT 12 offers, a reusable alternative.
  • Invoice strings are designed for QR codes. Converting them to uppercase enables QR alphanumeric mode, reducing code density by roughly 45% and making scanning easier on low-quality cameras.

What Is Invoice Encoding?

Invoice encoding represents a Lightning Network payment request as a compact, self-contained string. Your node generates an encoded invoice when you want to receive a Lightning payment, giving the sender the amount, payment route, cryptographic hash that locks the funds and expiry time.

The BOLT specification defines the encoding format, specifically in BOLT 11. It uses the same Bech32 character set as Bitcoin SegWit addresses but carries far more data. A SegWit address is 42 to 62 characters long, while a Lightning invoice typically spans 200 to 500 characters or more, depending on how many routing hints it includes.

How It Works

A BOLT 11 invoice is a single Bech32-encoded string. The string has four parts: a human-readable prefix, a separator, a data section and a checksum.

Human-Readable Prefix

The prefix always starts with ln. A currency code and an optional amount follow:

The amount is a decimal integer followed by a multiplier suffix: m for milli (0.001), u for micro (0.000001), n for nano (0.000000001) or p for pico (0.000000000001). For example, lnbc2500u requests 2,500 microsatoshis worth of bitcoin (250,000 satoshis). If no amount is specified, you choose how much to pay.

Separator

The character 1 separates the human-readable prefix from the data part. On-chain Bitcoin addresses follow the same convention.

Data Section

The data section contains three components. The components are:

Tagged Fields

Each tagged field uses a type-length-value structure: a 5-bit type tag, a 10-bit data length measured in 5-bit groups, and the data itself. The key fields include:

Routing Hint Structure

Each routing hint entry is exactly 51 bytes. It describes one hop of a private route to the receiver:

Multiple entries within a single r field form an ordered route from a public node to the destination. Multiple r fields provide alternative routes. Many routing hints make invoices substantially longer, which directly increases QR code size.

Bech32 and Error Detection

Lightning invoices use Bech32 encoding, defined in BIP-173, with a carefully chosen 32-character alphabet: qpzry9x8gf2tvdw0s3jn54khce6mua7l. The character set excludes visually ambiguous characters like 0/O, 1/l/I and b/6, reducing transcription errors when you communicate invoices manually.

The 6-character BCH checksum guarantees detection of any error affecting up to 4 characters, with less than a one-in-a-billion chance of missing errors affecting more characters. Payment requests need this protection because a single wrong character could send funds to the wrong destination or make the invoice unpayable.

BOLT 11 uses the original Bech32 (BIP-173), not Bech32m (BIP-350). Bech32m was introduced to fix a length-extension weakness in original Bech32 and is used for Taproot on-chain addresses, but Lightning invoices retain the original encoding.

QR Code Representation

Lightning invoices are often shared as QR codes, especially at point-of-sale terminals and in mobile wallets. The BOLT 11 specification recommends converting invoice strings to uppercase when generating QR codes.

QR codes support an alphanumeric mode that encodes two characters into 11 bits (5.5 bits per character), compared with byte mode at 8 bits per character, so uppercase is more efficient. Bech32 is case-insensitive, so uppercasing loses no information but reduces QR code density by roughly 45%. Fewer modules (black and white squares) make the code easier to scan with lower-quality cameras.

Size remains a practical concern: a minimal invoice with no routing hints might be 250 characters and produce a manageable QR code. An invoice with four or five routing hints can exceed 500 characters, creating dense QR codes that struggle on older devices. The size limitation is one reason BOLT 12 offers were designed to be dramatically shorter: a typical offer is 50 to 100 characters, making it practical to print on business cards or display as a static QR code.

Comparison with On-Chain Address Formats

Both Lightning invoices and on-chain Bitcoin addresses use Bech32 encoding. They serve fundamentally different purposes:

On-chain addresses are lightweight pointers to a script condition. Lightning invoices are self-contained payment instructions with cryptographic authentication. Their richer content enables trustless payment routing across multiple hops but comes at the cost of length and single-use semantics.

Limitations and the Path to BOLT 12

Several design constraints in BOLT 11 invoice encoding drove the development of BOLT 12 offers. The main constraints are:

BOLT 12 addresses these issues with a three-step flow: offer, invoice request and invoice. Offers are static and reusable (prefixed lno1), support blinded paths for recipient privacy, and can be exchanged directly through the Lightning Network via onion messages. As of 2026, BOLT 12 has been merged into the Lightning specification and is supported natively in Core Lightning and Eclair, with LDK offering library-level support, while LND support remains experimental behind a feature flag.

Point-of-Sale Payments

Merchants generate a BOLT 11 invoice for each transaction and display it as a QR code. You scan with a mobile wallet, verify the amount and description, and pay. The embedded amount prevents overpayment, and the expiry field ensures stale requests are automatically rejected.

Programmatic Billing

APIs and services generate invoices dynamically for metered usage, per-request billing or one-time purchases. The self-contained format means clients need no prior relationship with the server because the invoice string contains all information needed to complete payment. Protocols like LNURL build on this by automating invoice generation behind HTTP endpoints.

Cross-Layer Swaps

Submarine swaps and similar protocols rely on the payment hash embedded in the invoice to atomically link a Lightning payment to an on-chain transaction. The hash serves as a shared secret that coordinates settlement across layers, enabling trustless movement of funds between the Bitcoin base layer and Lightning.

Invoice Expiry and Failed Payments

Invoices expire by default after one hour. If you attempt to pay an expired invoice, the payment fails. Applications that generate invoices well in advance of payment, such as email-based billing, must account for this constraint by extending the expiry or regenerating invoices on demand.

Invoice Size and Scanning Reliability

Invoices with many routing hints can exceed 500 characters, producing large QR codes. Dense QR codes may fail to scan on older devices or in low-light conditions. Wallet developers can mitigate this by limiting the number of routing hints included or by falling back to NFC or clipboard-based sharing.

Privacy Trade-offs

Every BOLT 11 invoice reveals the recipient's node public key, which is linkable to an IP address through the Lightning gossip protocol. For privacy-sensitive users, this is a significant concern. BOLT 12 offers with blinded paths provide a stronger privacy model by hiding the recipient's identity from the sender.

Single-Use Constraint

Reusing a BOLT 11 invoice is insecure: once the preimage is revealed to settle the first payment, anyone who knows it can claim subsequent payments locked to the same hash. Applications must never present the same invoice to multiple payers. For scenarios requiring a static payment identifier, alternatives like LNURL, keysend or BOLT 12 offers are appropriate.

The research article on Lightning invoices: BOLT 11 vs. BOLT 12 provides a deeper comparison. It examines the BOLT 11 and BOLT 12 invoice formats.

The glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.

0

← All 1876 glossary terms