How Tor Works: The Complete Technical Guide 2026

A deep technical exploration of the Tor network: onion routing mechanics, the ntor handshake, v3 onion services, threat models, and pluggable transports.

On this page

The Tor (The Onion Router) network remains the foundational protocol for low-latency, decentralized anonymity on the public internet. By decoupling network-layer routing metadata from application-layer payloads, Tor prevents intermediate network observers, internet service providers (ISPs), and remote destinations from constructing a unified profile of client identity and behavior. Understanding the mechanics of Tor requires examining its cryptographic primitives, cell serialization mechanisms, consensus protocols, and threat models through a rigorous engineering lens.

Core Architecture and Relay Hierarchy

Tor operates as an overlay network spanning thousands of volunteer-run nodes known as relays. Unlike single-hop proxy servers or commercial Virtual Private Networks (VPNs), which require implicit trust in a centralized provider, Tor distributes trust across three distinct nodes in a virtual circuit: the Guard (Entry) relay, the Middle relay, and the Exit relay.

The Three-Hop Circuit Paradigm

  • Guard/Entry Relay: The initial point of contact for the client. The Guard sees the client’s real IP address but cannot decrypt the application payload or read the final destination address. Tor employs persistent "Entry Guards" (typically kept for 2 to 3 months) to defend against profiling and long-term statistical enumeration attacks.
  • Middle Relay: Positioned between the Guard and Exit nodes. The Middle relay sees only the encrypted transit traffic flowing between the Guard and the Exit. It knows neither the originating client IP nor the final recipient, neutralizing relay collusion unless an adversary controls all three path nodes.
  • Exit Relay: The termination node of the Tor circuit. The Exit strips the final cryptographic layer and transmits the raw or TLS-encrypted payload to the target destination server. The destination observes the Exit relay’s IP address as the origin of the connection. Exit relays do not know the client’s identity.

The Consensus and Directory Authorities

To construct paths dynamically without relying on a centralized database that could be poisoned, Tor relies on a distributed cluster of Directory Authorities (DirAuths). Currently, roughly nine trusted authorities independently test, monitor, and measure the state of the network. Every hour, these authorities exchange status votes and compute a deterministic, cryptographically signed network-status document known as the consensus.

Modern Tor clients download optimized summaries called microdescriptors rather than the full directory documents. A microdescriptor contains only the relay’s cryptographic identity fingerprint, its IP addresses, ports, onion key, and exit policies, drastically reducing bandwidth overhead while preserving integrity verification through cryptographic hashes embedded in the signed consensus.

Cryptographic Layering and Circuit Construction

Tor circuits are constructed incrementally using a process called telescoping. The client negotiates ephemeral keys with each relay sequentially, ensuring that intermediate hops only have visibility over their immediate predecessor and successor.

Cell Format and Serialization

Communication within the Tor network is standardized into fixed-size packets called cells. In link protocols v4 and v5, standard relay cells are precisely 514 bytes in length to minimize packet-size fingerprinting:

+---------+-----+---------+---------+--------+------------------+
| CircID  | Cmd | StreamID| Digest  | Length | Data Payload     |
| (4 B)   | (1B)| (2 B)   | (4 B)   | (2 B)  | (498 Bytes)      |
+---------+-----+---------+---------+--------+------------------+

Variable-length cells (such as VERSIONS and CERTS) exist purely during initial link-level TLS negotiation between nodes, after which fixed cells handle all routing, circuit management, and data streaming.

The ntor Handshake

Legacy implementations relied on the TAP (Tor Authentication Protocol) handshake, which used RSA-1024 and Diffie-Hellman over multiplicative groups. Modern Tor networks exclusively use the ntor handshake (and its post-quantum successors under active evaluation), an authenticated key-exchange mechanism based on Curve25519, HKDF-SHA256, and HMAC-SHA256.

  1. Client to Guard: The client sends a CREATE2 cell containing its ephemeral Curve25519 public key. The Guard computes the shared secret, generates its own ephemeral key, and replies with a CREATED2 cell containing the public component and an HMAC proving identity key possession.
  2. Telescoping to Middle: With a forward-secure channel open to the Guard, the client sends a RELAY_EARLY cell containing a RELAY_EXTEND2 payload addressed to the Guard, instructing it to extend the circuit to the chosen Middle relay.
  3. Telescoping to Exit: The client repeats the extension handshake through the established two-hop tunnel to bind the Exit relay.

At the end of this process, the client shares distinct symmetric keys (traditionally AES-128-CTR or AES-256-CTR, combined with running digests) with the Guard ($K_{G}$), the Middle ($K_{M}$), and the Exit ($K_{E}$). Outbound payloads are encrypted sequentially from outside in: $Enc_{K_{G}}(Enc_{K_{M}}(Enc_{K_{E}}(Payload)))$. As the cell traverses each hop, the corresponding relay strips off its specific layer of encryption (an "onion peel") and forwards the inner payload.

Onion Services (v3 Protocol)

Tor Onion Services (formerly hidden services) provide end-to-end authenticated, encrypted connectivity without exposing the hosting server's IP address or requiring open inbound firewall ports. The v3 onion protocol mitigates the weaknesses of the deprecated v1 and v2 formats by using modern cryptographic standards.

Addressing and Key Blindings

A v3 onion address is a 56-character Base32 string. It is not an arbitrary label; it encodes the service’s raw 32-byte Ed25519 public key, a 2-byte checksum, and a 1-byte version field:

[ 32-byte Ed25519 Public Key ] + [ 2-byte Checksum ] + [ 0x03 Version Byte ]
                            |
                   Base32 Encoding
                            |
           v53...example...d4.onion (56 characters)

To prevent malicious Distributed Hash Table nodes (HSDirs) from harvesting onion addresses, the v3 protocol incorporates key blinding. The public key published to the HSDir ring is derived dynamically using a daily-rotating scalar derived from the real public key and current UTC timestamp. Nodes hosting the descriptor cannot deduce the actual identity of the hidden service.

The Rendezvous Sequence

Establishing a connection between a client and an Onion Service executes across an orchestrated multi-step handshake:

  1. Service Publication: The Onion Service establishes persistent outbound circuits to several relays designated as Introduction Points. It signs an Onion Descriptor containing its blinded keys and introduction point details, uploading it to the HSDir ring.
  2. Client Query: The client decodes the target .onion address, computes the current blinding factor, and fetches the descriptor from the corresponding HSDir.
  3. Rendezvous Point Establishment: The client builds a standard three-hop circuit to an arbitrary relay and designates it as the Rendezvous Point (RP), provisioning it with a secret one-time authorization token (the rendezvous cookie).
  4. Introduction: The client constructs an encrypted introduction cell containing the RP’s identity and the cookie, sending it to one of the service’s Introduction Points via another three-hop circuit.
  5. Service Connects: The Introduction Point relays the request to the hidden service. The service builds a three-hop circuit to the chosen Rendezvous Point and presents the cookie.
  6. Circuit Merging: The Rendezvous Point connects both three-hop circuits end-to-end. The result is a 6-hop path where neither the client nor the server ever learns the other’s network coordinates.

Threat Models, Passive Attacks, and Network Realities

Tor is engineered primarily as a defense against localized, non-global adversaries. It does not provide absolute protection against an attacker capable of observing all traffic globally in real time.

End-to-End Correlation

If an entity (such as a state intelligence agency or an international consortium of transit tier-1 autonomous systems) monitors both the link between the client and the Guard relay AND the link between the Exit relay and the destination server, they can apply statistical correlation algorithms:

Traffic correlation does not require payload decryption. By analyzing packet inter-arrival times, bandwidth bursts, and cross-correlating transmission intervals over time, a statistical match can deanonymize an active session within dozens of transmitted cells.

Website Fingerprinting and Circuit Padding

Even when a user’s traffic is encrypted inside TLS and Tor cells, resource loading patterns (e.g., HTML structure, cascading stylesheets, parallel image fetches) generate distinct packet signatures. Local adversaries (such as a malicious local ISP) can use machine-learning classifiers to compare the observed stream of 514-byte cells against pre-recorded traces of known websites.

To resist website fingerprinting, Tor utilizes the WTF-PAD (Website Traffic Fingerprinting Protection with Adaptive Directed Padding) subsystem. WTF-PAD injects non-data padding cells during connection idle states and burst delays according to stochastic state machines, flattening detectable packet distributions without consuming excessive network overhead.

Censorship Circumvention: Bridges and Pluggable Transports

When authoritarian network perimeters enforce deep packet inspection (DPI) or block public Tor Directory Authority and Guard IP lists, clients must route initial traffic through unlisted relays (Bridges) running Pluggable Transports (PTs).

obfs4 (The Obfuscator)

The obfs4 transport removes all predictable protocol signatures from the wire. It leverages Elligator2 encoding to map Curve25519 public keys onto points that are computationally indistinguishable from uniform random noise. A DPI firewall inspecting an obfs4 handshake observes pure entropy, preventing automated heuristic classification or active probing attacks.

Snowflake

Snowflake routes client traffic through a dynamic network of ephemeral, browser-based WebSockets and WebRTC proxies. When an entry request is initiated:

  • The client sends an encrypted signal to a central Broker via domain fronting or fast-flux Rendezvous pipelines (such as Google AMP cache or AWS CloudFront).
  • The Broker locates an active volunteer running a Snowflake extension in a commodity web browser and negotiates a peer-to-peer WebRTC Data Channel between the user and the volunteer.
  • The volunteer forwards the received Tor traffic to a dedicated Snowflake bridge. Because WebRTC traffic looks identical to ordinary video/audio conferencing data, DPI platforms cannot easily filter it without breaking widespread consumer communication services.

Defensive Operational Security for Practitioners

Protocol-level anonymity is easily undermined by application-level leakage. Researchers, journalists, and security practitioners must enforce strict operational hygiene when routing through Tor.

  • Application Layer Containment: Standard browsers leak platform characteristics, canvas rendering metrics, WebGL signatures, and local network routes through WebRTC. Use the official Tor Browser, which isolates the JavaScript runtime, enforces uniform user-agent and screen dimensions, disables direct network primitives, and implements per-tab first-party circuit isolation (SOCKS5 username/password auth isolation).
  • End-to-End TLS Enforcement: An Exit relay can observe and manipulate cleartext HTTP or unencrypted DNS requests. Tor anonymizes network transport; it does not replace cryptographic data integrity. Always verify that HTTPS/TLS is actively negotiated at the application layer to block Exit-node sniffing or man-in-the-middle attacks.
  • Layered Isolation Environments: In high-threat operational contexts, run Tor through dedicated sandboxed environments such as Tails (an amnesic live OS that routes all system traffic through Tor via strict iptables rules) or Whonix (a dual-VM architecture where the "Workstation" has no physical network interface and can only communicate through an isolated "Gateway" VM). This prevents malware with local shellcode execution from reading the underlying host IP.

Conclusion

The Tor network is not magic; it is an applied cryptographic protocol balancing latency, throughput, and privacy across an untrusted substrate. By distributing trust across decentralized relays, executing ephemeral key-exchange handshakes, and continually upgrading to primitives resistant to metadata leakage and traffic analysis, Tor remains the preeminent defensive technology for digital self-defense and confidential communication across hostile networks.

Keywords
Tor networkonion routingntor handshakeprivacy technologyonion services v3traffic analysispluggable transportscryptography