I believe the gist is that back in ye olden times when everybody was just throwing their sewage into the river, that beer was less likely to kill you because it's boiled before it's fermented. I don't think they made the connection to boiling, but rather knew beer was a safer drink.
I'm spouting this off from memory without looking it up, so no guarantee I'm correct.
It's not just the boiling process. The alcohol in beer is anti-bacterial which allows the water to remain safer to drink for longer.
It wasn't beer in many cases. Grog is basically rum, water, and limes/citrus which help sailors prevent scurvy whilst also protecting them from bacterial infections. I don't believe they boiled the water at all in that case. I believe it was just mixed all together.
Is that proven about the alcohol level being antibacterial? Beer is pretty low on alcohol, even if they did strong beers back then, it would land around 10-12% or so. I am not sure that is enough to do anything to bacteria. Rum or other strong spirits, definitely yes.
To be fair, that beer was also generally much milder than modern beer, between 1-2% alc per volume (in Europe) , at least per historians and research papers I've read.
Edit: also most of those historians whose books I refer in this context are mostly Finnish, Swedish or German, so that should give some idea about my biases/sources. Its different in the Pacifics and Western Africa, I know.
You're going to get downvotes for not citing sources. You'll also get downvotes for citing a reddit comment. People who are here tend to not want to go there, and people commenting there aren't considered experts, which is why sources are required.
I clicked through and that person does cite references, but they use two books, and zero links. This is largely seen as not credible enough on the internet. People like citations, but want to be able to review the data themselves, thus disliking "trust me or buy this book."
As an effort to demonstrate how you can do the thing without making people downvote you (and definitely, definitely never complain about or mention the downvoting or you'll get more!) I have a reply.
I did a quick Google search for "did people in the middle ages drink beer instead of water" and got this articld which has several citations and says, "many did. Probably not everyone, and probably not all those who did were doing it because they thought it was healthier." Which I personally liked, because it's not the kind of absolutist view of huge populations I tend to find difficult to believe.
Normally I wouldn't cite reddit. But askhistorians has a higher threshold for their answers. The links idea seems to be a catch-22 because you fall into "trust me or this random guy on the internet." But alas, thank you for the reply.
In the case of sailors, where water was needed for extended voyages, transporting water in casks was impossible as it developed algae and would spoil quickly, becoming a health hazard. They added alcohol to make it not only more palatable but to prevent spoilage.
That's the definition of drinking alcohol because it's cleaner.
And unfortunately beer won't save us from the things most likely to make modern / near future water impotable. Except to the extent it makes us not care.