Typically what happens is that after you provide user id and password, a cookie is created on your machine that contains a session id mapped to a unique long-lived session on the server. Each time you send a request to the server, the session id cookie is sent along with it, and the server knows who you are and what you already did in the session previously. Logging out deletes the session on the server, rendering the session id cookie invalid. Trying to use a session cookie with a session that no longer exists on the server gets you the dreaded "session expired" message.
Generally this scheme is pretty secure, with one exception. The cookie can only be set by the server you're logging into, so it cannot be faked. The session id is long and random, so it cannot be guessed. A well-designed site does not store your password in the session cookie, since there's no real reason to do that. But here's the exception: if someone can listen in on your traffic (e.g. wifi) they can snoop the session id and hijack the session. The only complete defense against that is running everything across SSL, not just the login. Simply put, wrapping only the login in SSL protects your password, but not your session. Luckily SSL is so cheap these days that using it for everything is a no-brainer for most sites.
That's something entirely different from how to do authentication in the first place. It's possible to completely decouple the service you are logging into and the service that provides authentication, to the point where the two services only communicate across the user's browser. SAML does this by leveraging public key cryptography. For example (with handy diagram):
http://www.novell.com/communities/node/ ... %20process
In the end though, no matter how fancy the authentication model, it always comes down to having session cookies in the browser.