From Wikipedia:

An ad server is a computer server, specifically a web server, that stores advertisements used in online marketing and delivers them to website visitors.

The content of the webserver is constantly updated so that the website or webpage on which the ads are displayed contains new advertisements — e.g., banners (static images/animations) or text — when the site or page is visited or refreshed by a user.

In addition, the ad server also performs various other tasks like counting the number of impressions/clicks for an ad campaign and report generation, which helps in determining the ROI for an advertiser on a particular website.

Ad servers come in two flavors: local ad servers and third-party or remote ad servers. Local ad servers are typically run by a single publisher and serve ads to that publisher’s domains, allowing fine-grained creative, formatting, and content control by that publisher. Remote ad servers can serve ads across domains owned by multiple publishers. They deliver the ads from one central source so that advertisers and publishers can track the distribution of their online advertisements, and have one location for controlling the rotation and distribution of their advertisements across the web.