How Big Can a Web Cookie Be?

Computer
PhotoAlto/Odilon Dimier/Getty Images

A web cookie (often just called a "cookie") is a small piece of data that a website stores in a user's web browser. When a person loads a website, the cookie can tell the browser information about their visit or previous visits. This information can allow the site to remember preferences that may have been set during a previous visit or it can recall activity from one of those previous visits.

Have you ever been to an E-commerce website and added something to the shopping cart, but failed to complete the transaction?

If you returned to that site at a later date, only to find your items waiting for you in that cart, then you have seen a cookie in action.

The Size of a Cookie

The size of an HTTP cookie (which is the actual name of web cookies) is determined by the user agent. When you measure the size of your cookie, you should count the bytes in the entire name=value pair, including the equal-sign.

According to the RFC 2109, web cookies should not be limited by user agents, but the minimum capabilities of a browser or user agent should be at least 4096 bytes per cookie. This limit is applied to the name=value portion of the cookie only.

What this means is that if you're writing a cookie and the cookie is less than 4096 bytes, then it will be supported by every browser and user agent that conforms to the RFC.

Remember that this is the minimum requirement according to the RFC. Some browsers may support longer cookies, but to be safe, you should keep your cookies under 4093 bytes.

Many articles (including a previous version of this one) has suggested that staying under 4095 bytes should be sufficient to ensure full browser support, but some tests have shown that certain newer devices, like the iPad 3, come in a little lower than 4095.

Testing for Yourself

A great way to determine the size limit of web cookies in different browsers it to use the Browser Cookie Limits test.

 

Running this test in a few browsers on my computer, I got the following information for the latest versions of these browsers:

  • Google Chrome - 4096 bytes
  • Internet Explorer - 5117 bytes
  • Firefox - 4097 bytes

Edited by Jeremy Girard

Format
mla apa chicago
Your Citation
Kyrnin, Jennifer. "How Big Can a Web Cookie Be?" ThoughtCo, Jun. 6, 2017, thoughtco.com/cookie-size-limit-3466810. Kyrnin, Jennifer. (2017, June 6). How Big Can a Web Cookie Be? Retrieved from https://www.thoughtco.com/cookie-size-limit-3466810 Kyrnin, Jennifer. "How Big Can a Web Cookie Be?" ThoughtCo. https://www.thoughtco.com/cookie-size-limit-3466810 (accessed December 15, 2017).