@iant has given you a very clear reply for the bulk of your question. To answer your last sentence, given the zoom,x,y portion of the URL, a tile server that also renders the tiles will compute the bounding box of the given tile and then use a renderer with a style definition to generate the tile. A very common renderer is Mapnik. An alternative is that the tiles are produced 'up-front' (for example by GDAL). Other renderers are available.
The renderer uses the style definition to call the GIS data from files or databases and then creates a raster image based on the style for each layer (and the layer order) limited to the bounding box, much like making a map in QGIS or ArcGIS. This image is then sent to the user and usually simultaneously cached to disk to speed up the process next time.
EDIT re bounding boxes
The tiles are based on a grid, and usually conform to a well known grid defined as part of the TMS or WMS protocol. Other grids can be used but the convention is to start with a single square tile that covers the entire globe of side 256 x256 pixels. That is zoom level 0. Then for each zoom level increment subdivide the tile by powers of two (so z1 has two tiles, z2 has four and so on). If you scroll down in the link you posted you will actually find information on defining the bounding box (bbox) assuming the standard powers-of-two grid system. The bbox (or a meta tile based on it) is indeed used to fetch the data from a database, raster or shapefile etc. Have a look at Getting Started tutorial for Geoserver as this will help you understand what's going on. Geoserver is an excellent and open source package that renders, serves and caches tiles. I recommend you actually set up an instance of Geoserver locally on your PC as there's nothing like actually doing it to really understand something.