Cookies are a piece of data sent from a website and stored in your browser's memory.
Cookies can be required to allow a web to function properly as websites are stateless (they don't remember user information from one internal page to another) but sometimes they are used to track user actions within one web or across multiple webs in order to collect usage information or identify interests and map behavior to be able to offer relevant advertisements.
Necessary cookies are used to make a website function properly, they are generally not used for tracking and are not shared between webs.
The most common necessary action performed using a cookie is user authentication. When you log in to any website, a cookie is stored in your browser including some piece of data used by the web to remember who is authenticated when you go to another internal page or refresh the site.
Cookies are also used so that a web knows what's in your shopping cart, store user settings and more.
Analytical cookies are not necessary but are used to collect valuable information on how a website is being used, identify issues and figure out what needs to be improved on the site and what content is useful. The information collected is in most cases anonymous but some analytics services collect information that can be used to identify the user.
Marketing cookies are used to track visitors across websites to profile user behavior and allow publishers to display relevant advertisements.