How Tor Works, from the First Relay to an Onion Service
You open a website through Tor. The website receives a connection from the last Tor relay, the exit. The first relay, the guard, sees a connection from you. How did the request get from one to the other?
The Tor software on your device, called the client, builds a route through servers called relays. This route is a circuit. A relay on this circuit sees its adjacent hops and forwards traffic between them. Before building a circuit, the client verifies a map of the relays it can use. The kind of destination then determines which circuits the client needs.
Follow a request to a website
The first network map starts with a cold client. A server hands it a relay list. The client already has the information it needs to tell a signed network view from a list the server made up.
Choosing and building a circuit follows one new route to a website. The client chooses the exit first because the destination constrains that relay. To build the circuit, it starts with the guard, then asks the last relay on the circuit to add the next hop.
What a circuit carries follows traffic to the site and back. Tor sends the stream’s bytes in relay cells. The exit opens its own connection to the destination, and the browser’s encrypted session with the site carries on through the circuit and the exit’s connection to the site.
Follow a request to an onion service
Finding an onion service starts with a .onion address. The address gives the client a public key. A rotating directory lookup returns instructions for sending the service a message.
Meeting at a rendezvous follows that message. The client picks a relay as a meeting point. The service builds a circuit to the same relay. The relay joins them, and the two endpoints finish a handshake before sending application data.
Change what the observer can see
Bridges and pluggable transports look at the first connection from the client’s network. Blocking a known relay address and recognizing the traffic are two separate decisions a censor can make.
Who can see what takes the original request and moves the observer. A relay, a website and someone watching both ends have different evidence. Logging in changes what the site learns again.
The Tor protocol specification and onion service overview cover the two paths in the specification.