Microsoft 365 creates a domain for you, like contoso.onmicrosoft.com, when you sign up with the service. The user ID that you create when you sign up includes the domain, like alan@contoso.onmicrosoft.com.
If you want to have your email look like alan@contoso.com: buy the domain or just follow the steps in Add your users and domain to Microsoft 365 if you own it already.
You can replace your onmicrosoft.com domain after sign-up. While you can’t rename or remove an existing onmicrosoft.com domain, you can create a new one and make it your default onmicrosoft.com domain (your “fallback domain”). For example, if the initial domain you chose was fourthcoffee.onmicrosoft.com, if needed you can create a new onmicrosoft.com domain called fourthcoffeecorp.onmicrosoft.com and set it to be your fallback domain.
You might not be able to change your SharePoint domain name. Your SharePoint domain name is based on your onmicrosoft.com domain name. The ability to change the SharePoint domain name is available in public preview for organizations whose total SharePoint sites and OneDrive accounts number fewer than 1000.
You can't remove your onmicrosoft.com domain. Microsoft 365 needs to keep it around because it's used behind the scenes for your subscription. But you don't have to use the domain yourself after you've added a custom domain. If you choose to create a new onmicrosoft.com domain, it cannot be removed. You are limited to five onmicrosoft.com domains in your Microsoft 365 environment, so make sure to check for spelling and to assess your need if you choose to create a new one.
You can keep using the initial onmicrosoft.com domain even after you add your domain. It still works for email and other services, so it's your choice.