This is called Single sign-on (SSO). When you click the sign-in button on
google.com it redirects you to
accounts.google.com with a bunch of url-encoded params. We only care about the
continue param, which represents the page where the sign-in button was clicked.
Next, you sign-in to your account at
accounts.google.com sets a cookie for
google.com. It can do this since this is its super domain. It then redirects you back to the page where you clicked sign-in (
From that point on,
google.com can recognize you. As well as all of its sub domains.
But how can
youtube.com recognize you? It is not a subdomain of
The point is that when
accounts.google.com redirects you back to
continue param. Before that it redirects you to
token params. And
accounts.youtube.com in its turn sets a cookie for
youtube.com and finally redirects you to
youtube.com recognizes you. You can clear cookies specific to
youtube.com to exit only from youtube.