How Onion Routing Works
What you'll learn: How Tor achieves anonymity through layered encryption and prevents adversaries from linking your origin to your destination.
The Core Mechanism
Onion routing creates anonymity by wrapping your data in multiple layers of encryption—like layers of an onion—and routing it through a chain of relay nodes. Each relay can only decrypt one layer, revealing just the next hop's address, never the full path.
When you send traffic through Tor, your client first selects three random relays: an entry (guard) node, a middle relay, and an exit node. This three-hop circuit is your encrypted tunnel.
Circuit Construction and Layered Encryption
Your Tor client builds the circuit incrementally using the Diffie-Hellman key exchange (building on forward secrecy concepts you learned earlier):
- With the entry node: Establish shared secret keys
- Through the entry, negotiate with middle: Create second encryption layer
- Through both, negotiate with exit: Add third layer
Now your data gets encrypted three times, outermost-to-innermost: exit → middle → entry.
As your encrypted packet travels, each relay peels off one encryption layer:
- Entry node removes outer layer, sees only "send to middle node"
- Middle node removes next layer, sees only "send to exit node"
- Exit node removes final layer, forwards to destination
No single node knows both your source and destination. The entry knows you but not your destination; the exit knows your destination but not you.
Preventing Traffic Correlation
While each relay sees only its neighbors, a global passive adversary watching both entry and exit could correlate timing patterns. Tor mitigates this through circuit rotation (every 10 minutes) and padding techniques, though timing attacks remain a research challenge—hence why Tor architecture distributes trust across jurisdictions.
Key Takeaway: Onion routing achieves anonymity through layered encryption and multi-hop circuits where no single relay knows the complete path, preventing traffic analysis by distributed adversaries.