First of all you start with the DNS settings.
have an A record for mydomain.tld pointing to
1.2.3.4
so when you enter mydomain.tld into a browser, it'll resolve to that IP.
The corresponding machine associated with that specific IP will have a webserver installed and configured to serve requests to that specific mydomain.tld.
See the virtual host docu linked by PehJota.
Of course you can also have multiple web servers installed.
DNS:
have an A record for mydomain.tld pointing to 1.2.3.4
have an A record for test.mydomain.tld pointing to 1.2.3.4
server:
have apache configured to serve incoming requests for mydomain.tld in the config settings (RH based: /etc/httpd/conf.d/mydomain.tld.conf Debian based: /etc/apache2/sites-enabled/mydomain.tld which is a symlink to /etc/apache2/sites-available/mydomain.tld )
have nginx configured to serve incoming requests for test.mydomain.tld in the config settings (similar location setting for Debian based, not sure right now for RHEL based).
Through both methods you have one physical machine serving incoming requests to different websites, either by one web server having multiple virtual hosts configured, or by having different web servers installed (for various reasons, e.g. using a light weight server such as lighttpd for serving static files, such as css,jpgs, etc.)
You do also get the situations where different sub domains point to different machines
DNS:
have an A record for mydomain.tld pointing to 1.2.3.4 (machine A)
have an A record for mail.mydomain.tld pointing to 10.20.30.40 (machine A)
machines:
machine A will serve only mydomain.tld
machine B will serve only mail.mydomain.tld probably a webmail interface such as squirrelmail, horde, roundcube
presumably having the mail on a different machine, you're probably also running the mail system there too, such as postfix/dovecot.
DNS:
have an MX record for mail.mydomain.tld pointing to 10.20.30.40 (machine B)
machine:
have postfix/dovecot configured to handle incoming mail to @mydomain.tld mail addresses
have the webmail software configured to access those mails upon successful login.
you can have as many subdomains on one machine as you want (or machine's capable of) as well as having as many subdomains resolving to as many machines you have (budget allows)
Having some subdomains pointing to different machines may depend on the services you're running, as well as the load taken by a site, etc. (many reasons for splitting up)
Then of course there are also wildcards, for where you don't have an A record set, such as for
thisdoesnotexist.mydomain.tld
In that case you can have your config set to point to a generic page, or redirect to a different existing site.
k, may have gone overboard here a little, but I think you get the jist(sp?) of it
