At a large scale, Drupal does three things when a page on your website is requested. The first is that Drupal checks which files and libraries are necessary to collect the information on the page – and how much of the information the requesting user is allowed to access. The second is to actually collect all the information, which usually involves quite a bit of querying and poking in the database. The third and final step is to take the big, naked array of collected data and dress it up with different templates and HTML tags to make it presentable in a web browser.
TIP: Most Drupal themes outputs (X)HTML, but nothing in Drupal forces the content to be presented as a web page. A theme could for example present content as spoken text, or as XML files processed by other applications.