There are two types of cookies:
1) Server side cookie
2) Client (HTTP) side cookie
When you clear cookies from browser, it clears only client side cookies (cookies on your machine). And yes, there is expiration time set for all cookies.
Some information for you:
Client side cookies
Cookies are key/value pairs used by websites to store state informations on the browser. Say you have a website (example.com), when the browser requests a webpage the website can send cookies to store informations on the browser.
Browser request example:
GET /index.html HTTP/1.1 Host: www.example.com Example answer from the server:
HTTP/1.1 200 OK
Content-type: text/html
Set-Cookie: foo=10
Set-Cookie: bar=20; Expires=Fri, 30 Sep 2011 11:48:00 GMT
... rest of the response
Here two cookies foo=10 and bar=20 are stored on the browser. The second one will expire on 30 September. In each subsequent request the browser will send the cookies back to the server.
GET /spec.html HTTP/1.1
Host: www.example.com
Cookie: foo=10; bar=20
Accept: */*
SESSIONS: Server side cookies
Server side cookies are known as "sessions". The website in this case stores a single cookie on the browser containing a unique Session Identifier. Status information (foo=10 and bar=20 above) are stored on the server and the Session Identifier is used to match the request with the data stored on the server.
Check here for more details:
What is the difference between server side cookie and client side cookie?
When session cookies are cleared, they are removed from the client (your machine). Now, the server can't identify you since it doesn't know the session id which was in the cookie you cleared recently, and so it looks like your session is cleared.
Part of credit goes to the guy that answered that question!!