A good place to begin—how modern Google search works:

Mission of Google’s search: “organize the world’s information and make it universally accessible and useful” — like an advanced yellowbook. Google declared their mission in Our approach to Search, including 6 key aspects:

(1) Deliver the most relevant and reliable information available.

(2) Maximize access to information

(3) Present information in the most useful way

(4) Protect your privacy

(5) Sell ads, nothing more

(6) Help creators succeed online.

Many years ago it was PageRank. Nowadays,

  • Googlebots crawl the web and find out what pages exist. See Crawling by Google.
  • Google analyze the pages’ content and collect signals about the pages. This step is called Indexing, as defined and explained by Google
  • When a user enters a query, Google serves search results: by searching the index for matching pages and return the results based on relevancy and quality.

Additionally Google’s Ads’ are also served based on their quality (not merely the amount of money the advertiser is willing to offer). Google charge on Click-Throughs, hence they want to maximize click-throughs of ads instead of impressions. And click-throughs are associated with Ad’s quality. Somewhat this is aligned with its organic search’s mission.

reference

How Search Works. Google Search. https://www.google.com/search/howsearchworks/

In-depth guide to how Google Search works. Google Search Central. https://developers.google.com/search/docs/fundamentals/how-search-works

Google ads quality score. Google Ads Help. https://support.google.com/google-ads/answer/6167118?hl=en&visit_id=638647699014100656-1255551433&rd=1