Cookies are small text files created by web servers that are stored in web browsers. They allow servers to maintain state between HTTP requests from a browser. There are two types of cookies - permanent/persistent cookies that are stored on a user's computer and not deleted when the browser closes, and session/transient cookies that are stored in memory only during a user's browsing session and deleted when the browser closes. Cookies are commonly used to track website activity, for online shopping carts, and to provide personalized web pages. They work by the server adding a cookie to the response which gets stored in the browser cache, and the browser then sends that cookie back with subsequent requests so the server can recognize the user.