A cookie is a small piece of information that the browser writes on the device (computer, mobile, tablet, smart screen, etc) of the user. There are first party cookies or third party cookies. First party cookies are the ones that belong directly to the website you are browsing. If you visit ebay.com, all the cookies hosted in ebay.com are first party cookies. If you have a paypal cookie on ebay.com, this cookie will be considered a third party cookie, as it´s outside the domain. Same happen with all the cookies that collect audiences, like doubleclick, adform, google or facebook, for example.
Cookies are very important for online advertising as they are one of the keys for all the system. With the cookies, all the ad tech companies, like facebook and google, can identify the websites that one specific user see and match with other data sources, like your logins. This information can be used then, by advertisers, to target users.
Cookies allow advertisers to cap the number of impressions / exposures per user and measure all the interactions per user. Cookies are then what allow advertisers to be more intelligent when they advertise in a programmatic way.