Cookie is small information stored in test file on user’s hard drive by web server. Generally cookie contains personalized user data or information that is used to communicate between different web pages. Cookies are the user’s identity and used to track where the user navigated throughout the web site pages. The HTTP protocol used to exchange information files on the web is used to maintain the cookies. Whenever user visits the site or page that is using cookie, small code inside that HTML page (Generally a call to some language script to write the cookie like cookies in Javascript, PHP, Perl) writes a text file on users machine called cookie. There are two types of cookies written on user machine: session cookies, and persistent cookies.
Source: http://www.softwaretestinghelp.com/category/cookie-testing/