system
Given the following post, respond as if you're commenting on Reddit:
human
How a service can give a subdomain to each user?

When I was a teenager, I was surprised how blogger or other blogging services like wordpress allow you to have a subdomain. I experienced a lot and found some CMS's have their tricks to create some sort of "network" (Specially wordpress, it's called wordpress network if I'm right). 

But recently, I saw it's not only done by blogging services, but by PaaS, SaaS or DBaaS services as well. I am really curious about this. How can I make a web app I developed make a subdomain for each user?
gpt
The answers here aren't particularly direct. There are really two main options. For both of them you need to have a way to sign up a new entity (user, site, etc.) and make the subdomain available, such as adding it to a database. The main options:

1. As someone mentioned, you can have a wildcard entry in DNS that points to your server. This means all subdomains would be directed to that one same server. When a request comes in, it will include the desired domain in the HTTP request. Using that, the subdomain can be looked up in the database, and the appropriate redirection or content served up.

2. You run your own DNS that provides answers for any subdomain query under your domain. You can still respond in a way that provides a common server, as in #1, but also provide specific other servers for some subdomains. If you don't want to run your own DNS you could host these other specific addresses in some other DNS host, such as your internet providers, if they allow it.

Note that both of these options can be used together.