How does shared hosting work?

From the Wikipedia article:

Name-based
In name-based virtual hosting, also called shared IP hosting, the virtual hosts serve multiple hostnames on a single machine with a single IP address. When a web browser requests a resource from a web server using HTTP/1.1 it includes the requested hostname as part of the request. The server uses this information to determine which web site to show the user.

IP-based
In IP-based virtual hosting, also called dedicated IP hosting, each virtual host has a different IP address. The web server is configured with multiple physical network interfaces, or virtual network interfaces on the same physical interface. The web server software uses the IP address the client connects to in order to determine which web site to show the user. The primary reason for a site to use a dedicated IP is to be able to use its own SSL certificate rather than a shared certificate.