---
title: "Onion Routing — definition | Nuri Glossary"
description: "Each hop peels one layer and learns only the next hop, so no node sees the whole path."
lang: "en"
type: "glossary-term"
canonical: "https://nuri.com/glossary/onion-routing"
---

# Onion Routing

Each hop peels one layer and learns only the next hop, so no node sees the whole path.

## Basically

Onion routing hides the full path of a Lightning payment. Each node gets only the instructions it needs to pass the payment along.

## Key Takeaways

- Onion routing wraps payment instructions in layers of encryption. Each node can decrypt only its own layer, learning the previous and next hops but never the full path from sender to receiver.
- The Lightning Network uses Sphinx packets for onion routing. Their fixed-size encrypted payloads stop intermediate nodes from determining their position in the route or the total number of hops.
- Privacy is not absolute. Timing analysis, probing attacks and traffic correlation can partly deanonymise payments, while blinded paths and trampoline payments offer additional defences.

## What Is Onion Routing?

Onion routing is a privacy technique that encrypts a message in multiple layers, like the layers of an onion. Each processing node peels off one layer, revealing only where the message came from and where to send it next. No single node ever sees the complete route.
The concept originated in the 1990s at the U.S. Naval Research Laboratory and became widely known through the Tor network, which uses onion routing for anonymous internet browsing. The Lightning Network adopted a similar approach for payment routing. Its Sphinx construction protects the privacy of both senders and receivers in Bitcoin payment channels.
Onion routing prevents every forwarding node from learning the sender, receiver and amount. Forwarding nodes learn only what they need to perform their role: accept a payment from one channel and push it out through another.

## How It Works

Your node first calculates the full route to the destination when you initiate a Lightning payment. It then constructs a Sphinx onion packet that encodes instructions for every hop along the path. The construction process works from the inside out.
Each forwarding node receives the onion, derives the shared secret using its private key and decrypts its layer. The decrypted layer reveals the per-hop instructions: the next node to forward to, the amount and timelock to use, and the remaining, still encrypted onion to pass along.

## The Sphinx Packet Format

Lightning uses the Sphinx packet construction defined in BOLT #4. A Sphinx packet has three components.
The encrypted payload uses a stream cipher, ChaCha20, keyed with the shared secret. After decrypting, the node reads its own per-hop data from the beginning of the payload, shifts the remaining bytes left and pads them with pseudorandom filler bytes. The shift-and-pad process keeps the payload at exactly 1300 bytes, regardless of the node's position in the route.

## Per-Hop Payload Contents

Each hop's decrypted payload contains a set of fields encoded in Type-Length-Value (TLV) format. TLV encoding organises those fields by type, length and value.
The final hop's payload contains the payment secret, total amount and any additional application-level data instead of forwarding instructions. The payment secret proves that the payment was intended for this receiver. For recipients with private channels, the sender includes route hints in the onion construction to reach nodes that are not visible in the public graph.

## What Each Node Can and Cannot See

A forwarding node learns only the information revealed by its own encrypted layer. It sees the instructions required to handle its part of the route.
A forwarding node cannot determine the parts of the route hidden in the other layers. It cannot reconstruct information that its local view does not contain.
The difference between what a node can and cannot see gives onion routing its core privacy property. An adversary controlling one or two nodes in the path cannot reconstruct the full payment route from their local view alone.

## The 20-Hop Limit

The fixed 1300-byte payload limits Lightning routes to a maximum of 20 hops. Each hop consumes approximately 65 bytes of payload space with the modern TLV format, and the total must fit within the fixed allocation.
Two design reasons explain the limit. Together, they justify why routes cannot exceed 20 hops.
The 20-hop ceiling is generous for real-world use. The network's small-world topology means almost any two nodes are reachable within a handful of hops.

## Comparison to Tor Onion Routing

Both Lightning and Tor use layered encryption, but their designs differ significantly. Each system applies those layers in a different way.
Tor circuits are long-lived and carry many packets, making them vulnerable to traffic analysis over time. Lightning onion packets are single-use, and each payment creates a fresh packet with new ephemeral keys. The single-use design limits the window for correlation attacks but does not eliminate them entirely.

## Private Payments

Payment privacy is the primary use case. When Alice pays Bob through intermediate nodes Carol and Dave, Carol knows Alice sent something through her but does not know the destination. Dave knows he is forwarding to Bob but does not know the origin, and neither Carol nor Dave learns the full picture.
Payment privacy matters for Bitcoin layer-2 networks. Financial transactions should not be visible to every participant in the routing infrastructure.

## Multi-Hop Routing with Fees

Onion routing enables a decentralised fee market. Each node sets its own routing fees, and the sender embeds the correct fee amounts in each hop's encrypted payload. Nodes cannot see what other nodes are charging, which prevents collusion on fee extraction.

## Atomic Multi-Path Payments

Atomic multi-path payments (AMP) split a payment across multiple routes. Each partial payment carries its own onion packet with independent layered encryption. No single routing node sees the total payment amount, and intermediaries cannot correlate the partial payments.

## Blinded Paths and Receiver Privacy

Standard onion routing protects the sender well because forwarding nodes cannot identify the origin. The sender must know the receiver's node ID to construct the route. That requirement leaks the receiver's identity to the sender.
Blinded paths extend onion routing so the receiver provides a pre-encrypted route suffix. The sender constructs their portion of the onion and appends the blinded segment without knowing the final destination node. The sender therefore does not learn the receiver's identity, and forwarding nodes learn nothing about either endpoint.

## Timing Attacks

Onion encryption hides the contents of a payment, but it does not hide when payments occur. An adversary controlling two nodes on the same route can correlate an incoming HTLC at one node with an outgoing HTLC at the other by matching amounts, timing and hash values. All hops in a payment share the same payment hash, so a node appearing twice on the path can link both positions.
PTLCs (Point Time-Locked Contracts) are a proposed upgrade that would replace the shared payment hash with per-hop randomised points, using Taproot and Schnorr signatures. The upgrade would eliminate hash-based correlation while preserving atomicity.

## Probing and Network Analysis

Channel probing lets an attacker send fake payments that deliberately fail to infer channel balances across the network. Combined with knowledge of the network graph, an adversary can narrow down the possible senders for a payment by analysing which channels had sufficient balance to route it.
Onion routing prevents direct observation of the route, but it does not prevent inference-based deanonymisation. Network-level adversaries that can observe many nodes simultaneously pose the greatest threat to payment privacy.

## Route Length Inference

The fixed-size Sphinx packet prevents exact route-length determination, but timing can leak information. Payments routed through more hops experience slightly higher latency. A sophisticated adversary measuring HTLC settlement times at their node could make statistical guesses about whether they are near the beginning or end of a route.
Some implementations add small random delays to HTLC forwarding to reduce this risk. The delays create a trade-off between privacy and payment speed.

## Sender Knowledge Requirement

Source routing requires you, as the sender, to know the full network topology and compute the route yourself. You must have a reasonably current view of the channel graph, which can be resource-intensive for mobile or constrained devices. Trampoline payments delegate route computation to intermediate nodes, but they introduce a partial trust assumption: the trampoline node learns that a payment was requested, even if it does not learn the final destination.

## Error Reporting and Privacy Leaks

A failing node generates an error that propagates back to you when a payment fails mid-route. Shared secrets from the original onion encrypt these error messages, so only you can read them. The error structure can sometimes reveal which node failed, leaking partial route information to any node that observes the error timing.
The Lightning specification has evolved to address this problem with attributable errors. They let you cryptographically verify which node produced the error without leaking that information to intermediate nodes.
The article is for educational purposes only and does not constitute financial or technical advice. Privacy properties depend on implementation details and network conditions that change over time.
Part of the [Nuri glossary](https://nuri.com/glossary), which defines 1876 Bitcoin, Lightning, wallet, stablecoin and payment terms.
