Ok for subdomain it's easy. I guess it just looks up the subdomain:
blog5.site.com
=> explode('.', $_SERVER['REQUEST_URI'])...
But how does it do it for sub-directory setups? This should be interesting considering that pages, taxonomies and what not can take the first part of the part after the site domain name.
How can it distinguish between a inner blog, and a page of the primary blog? The only thing I could think of is database matching against the entire blog list, then if it fails match primary blog content, but that would be a really stupid thing to do because it seriously slows down the site...