DEV Community

Afzalur Rahman
Afzalur Rahman

Posted on

How Tor Works: Onion Routing Explained Step by Step Slug: how-tor-works-onion-routing-explained

How does Tor work? A step-by-step explanation of relays, layered encryption and onion services, plus what Tor can and cannot protect you from.
Short answer. Tor sends your traffic through three volunteer-run servers called relays: a guard, a middle relay and an exit. Your computer wraps the data in three layers of encryption and each relay removes only its own layer, so no single relay knows both who you are and what you are visiting.
Why Tor exists
Normally, every website you visit can see your IP address, and your internet provider can see which sites you contact. Tor was designed to separate those two facts. It is a network run by volunteers around the world that passes your connection through several hops so that no one point sees the whole picture.
The three relays
A normal Tor connection, called a circuit, uses three relays chosen by your Tor software: 1. Guard (entry) relay. The first hop. It sees your real IP address but not which website you are going to. Your Tor software keeps using the same guard for a long time rather than choosing a new one for every connection, which reduces some attack risks. 2. Middle relay. It passes traffic along. It knows neither who you are nor where you are going. 3. Exit relay. The last hop. It removes the final layer and connects to the website. It knows the destination, but not who is asking.
Layers like an onion
Before sending data, your Tor software agrees a separate secret key with each of the three relays. It then encrypts the data three times, first for the exit, then for the middle, then for the guard. Each relay peels off one layer and forwards the rest. This is why the technique is called onion routing, and why the Tor Browser has an onion logo.
What the exit relay can see
The exit relay connects to the destination website, so it can see the traffic that leaves Tor. If you visit a site using HTTPS, the content stays encrypted between you and that site, and the exit relay sees only that you connected to it. If you use plain HTTP, the exit relay could read the content. This is one reason to use HTTPS sites over Tor.
Onion services: sites inside Tor
Some websites live inside the Tor network and have addresses ending in .onion. These are called onion services. You and the service each build circuits to a meeting point inside the network (a rendezvous point), so the connection never leaves Tor and there is no exit relay. Modern version 3 onion addresses are 56 characters long. Older version 2 addresses were retired in 2021 and no longer work in current Tor Browser versions.
What Tor does not do
Tor is a strong privacy tool, not magic. It does not protect you if you log in to your personal accounts, because the website then knows who you are. It does not protect you from malware on your own device, or from mistakes such as revealing personal details. Researchers have also shown that very powerful observers who can watch both ends of a connection might be able to match traffic patterns. Your internet provider can usually see that you are using Tor, unless you use special bridges designed to hide that. And Tor is slower than a normal connection because of the extra hops.
Tor versus a VPN
A VPN sends all your traffic through one company’s server, so you must trust that single provider. Tor spreads trust across several volunteer relays so that no one of them sees everything. They solve different problems, and neither makes you invisible.
Why defenders care
Security teams, journalists and investigators need to understand Tor because attackers and privacy-seekers both use it. Knowing how it works explains why blocking it is hard, why monitoring it takes careful, lawful methods, and why investigations usually succeed through other evidence rather than “breaking” Tor.
Key takeaways
• Tor uses three relays: guard, middle, exit.
• Layered encryption means no single relay sees both who you are and where you go.
• Onion services stay inside the network and avoid exit relays.
• Tor is not magic: your behaviour, devices and accounts still matter.
Go deeper
Chapter 18, “Tor in depth: relays, circuits and onion services”, is free to read: Read Chapter 18. The full webbook: https://classji.in/learn/dark-web/chapters/ch18.html
Sources to check
• The Tor Project: “About Tor”, the Tor support pages and Tor Metrics (torproject.org).
• Dingledine, Mathewson and Syverson, “Tor: The Second-Generation Onion Router” (USENIX Security, 2004).

Top comments (0)