Think of it in this context:
Imagine a large [western] family. Instead of humans, however, picture a cluster of computers. Just as every person in a family has a common last name and a different first name...
- hostname is to domain name (in the networking world) as a person's first name is to that person's lastname/family-name.
Have you ever heard the saying,
Don't put all your eggs in one basket? Among other reasons, a computer admin. may wish to distribute various tasks across multiple (cloud) servers, e.g. pop.yourdomain.tld; smtp.yourdomain.tld; www.yourdomain.tld; cdn.yourdomain.tld; ns1.yourdomain.tld; ns2.yourdomain.tld; loadbalancer1.yourdomain.tld; loadbalancer2.yourdomain.tld; and so on.
In this example, the
xxx in
xxx.yourdomain.tld is the hostname. Where you're getting confused, I believe, is that every host, e.g. cdn.yourdomain.tld, can have more than one hostname (or, host alias); hence, why you often see the reference to
localhost on EVERY computer or cloud instance.
Our friends @ Google are also usually very helpful with questions such as this.