Subdomains are ultimately a configuration of DNS.
If you own www.example.com
- you can set the A record and host for that to 184.108.40.206 for example, on which a web server resides. NOW TECHNICALLY in this example "www" IS the subdomain.
Now lets say you have a second actually webserver, you could create a DNS entry for www2.example.com pointing to 220.127.116.11.
That's the basics.. you can move forward from there within your web server software by using the hosts configuration.. www & www2 could both point to the same IP address, however the server will interpret them to different locations.. perhaps
home/user1/html_root/ & home/user1/html_root/www2/
OR you could setup individual user or web accounts under the same domain.. here is an example of a configuration that I actually use
home/bob/html_root/ = bob.example.com
home/joe/html_root/ = joe.example.com
this is all however, if you run your own webserver, most hosting companies simplify all this within their admin cp's.