Black magic. Just kidding. When you visit a site with your web browser it sends a little nugget of information to that site called a “User Agent”. The user agent has a few minor pieces of information about your browser, platform, and OS version. Using this information a guess can be made about what Operating System your using.
Why is it a guess? The user agent your browser sends to the website can be changed very easily. It’s not to be trusted in any way, shape, or form as the truth, but most people generally use browsers who’s user agents have not been changed.
Why is it only generally? Sometimes the people that provide your internet access will modify this user agent so the website can not tell what your browser is or will set the user agent to a general browser type so the site will render the same for everyone. This is not the norm so don’t fret to much.