Syllabus Lesson 141 of 156 · Anonymity networks and traffic analysis
Anonymity networks and traffic analysis

Guards, exits and the first hop

Why it matters Of the three relays in a circuit, the first one is the only one that sees your real IP address. How Tor chooses that first hop decides how likely you are, over months of use, to hand your traffic to someone watching. It is a neat lesson in how small probabilities add up.

Think of choosing a taxi firm. If you pick a random firm every single night, then over a year you are almost certain to ride with the one dodgy firm in town at least once. If you pick one firm you have reason to trust and stick with it, you either got a dodgy one or you did not, and most people did not.

The danger: watching both ends

Onion routing stops any single relay from knowing both you and your destination. But suppose an observer runs, or can watch, both your first relay and your last relay. They see traffic go in at one end and come out at the other, and the timing matches. The next lesson shows how easily that matching works. So the question becomes: how often do you pick a bad first hop and a bad last hop?

Entry guard: a first relay your Tor client picks and then keeps using for a long time, instead of choosing a fresh first relay for every circuit.

Why a fresh first hop each time is worse

Say 5% of first hops (by the share of traffic they carry) are run by an observer. Each new random pick has a 1 in 20 chance of being bad. The chance of picking at least one bad first hop in n picks is 1 - 0.95 ** n:

for n in [1, 10, 50, 200]:
    print(n, "circuits:", round(1 - 0.95 ** n, 2))
# 1 circuits: 0.05
# 10 circuits: 0.4
# 50 circuits: 0.92
# 200 circuits: 1.0

Tor builds new circuits all the time, so with fresh first hops nearly every regular user would sooner or later be exposed. With a guard, you pick once: 95% of users are never exposed through the first hop at all. The unlucky 5% are exposed, but they would have been anyway. Tor keeps the same entry guard for months rather than choosing a new one per connection (checked October 2026).

The exit: the most visible relay

The exit is the relay that connects to the website for you, so the site sees the exit's IP address, not yours. That has three consequences:

  • The exit sees your destination and, without HTTPS, your traffic. Use HTTPS sites.
  • Some sites block or challenge traffic from known exits, because the list of exits is public.
  • Exit operators choose an exit policy: which ports and addresses they will connect to.

Exit policy: the rules an exit relay publishes about which kinds of connections it will make on behalf of users, for example web traffic only.

The middle relay knows the least: only the guard and the exit. It exists so the guard and exit never talk to each other directly.

Bridges: when even the first hop must hide

The list of ordinary relays is public, so a network that wants to block Tor can block them all. Bridges are unlisted entry relays, often combined with tools that make the traffic look like something else, so people on censored networks can still connect (checked October 2026).

A common misconception: "More hops means more anonymity, so ten relays beat three." Not really. The main attack watches the first and last hop; adding middles does not change who those are, but it does make every page slower. Three is the balance Tor chose.

Try it Work out the chance for your own numbers: in Python, try 1 - (1 - f) ** n with f = 0.02 and n = 365 (a new first hop every day for a year). Then compare it with a single pick, which is just f.

Recap

  • Only the first relay sees your IP address, so how it is chosen matters most.
  • Picking a fresh first hop each time makes it almost certain you eventually pick a bad one; a long-lived guard avoids that.
  • The exit sees your destination and, without HTTPS, your content; sites see the exit's address, not yours.
  • More hops add delay, not much safety: the danger is someone watching both ends.

Spotted a problem in this lesson? Report it

Code · runs in your browser
Output