It is done via a cookie (or actually several). These are small text files stored on your PC, that contain data used by websites. As well as their text content - which might be a userid, or hashed (encrypted) password - they also have an expiry date. Assuming you haven't set any other preferences in your browser, this expiry date can either be at the end of the session, or a particular date.
If you are using Firefox, you can view your cookies by selecting Edit > Preferences > Privacy, and clicking "show cookies". You should find an entry in the list for linuxquestions.org - expand this, and take a look.
I have (among others):
- bbpassword - contains my hashed password - expires 26/07/2009
- bbuserid - contains a numeric id (not my username) - expires 26/07/2009
- bbsessionhash - contains my current sessionid - expires at end of session
Cookies can be helpful, but there are also privacy issues (for instance, marketing companies can use "tracker cookies" to monitor your web activity). Firefox allows you to block cookies from particular domains (I have it ask me for each cookie, and block all from *.2o7.net, *.doubleclick.net, etc) or to set cookies to expire at the end of the session, whatever the expiry date.