To make sure your visitors do not get a 404 error when they type in your root domain (e.g. example.com), you will need to add a redirect in your DNS settings that point your root domain to include the www. (e.g. www.example.com)
Using www. as your subdomain
Connecting your naked domain
Within your DNS settings, you'll want to create a 301 redirect from the naked/root domain to a version of your domain including the www subdomain.
Each DNS handles redirects differently, so please reach out to your domain provider for any help on creating a redirect.