Once upon a time, Macs were believed to be the safest commercially-available computers and Apple was actually using this as a major selling point to justify its insanely high prices. Unfortunately, for the regular users, things seem to have changed lately and it has been proven that Macs, as well as their operating systems, aren't really that impervious to hacker attacks or malware infections. Furthermore, according to a recent report, things are getting worse.
Before you label me as an "Apple hater" let me make it clear that Macs are still a lot safer than Windows-powered PCs not only because of their software but also due to their hardware architecture which makes them immune to PCIe DMA attacks. However, according to a study published by McAfee, just in the first quarter of this year, the number of Mac machines infected by malware has grown by more than 50%. Moreover, the same report shows that this drastic growth is mostly caused by adware. So, whenever those big websites that we all like to visit tell you how good ads are and how we should all love watching them, you should know that they're not only annoying but also potentially dangerous for your Mac.
Unlike McAfee, I have no product to sell, so I'm going to tell you that the best way to protect yourself against this onslaught of dangers is to be mindful where you click while online. Try to stay away from websites that look fishy or that you're not sure about. Most of the websites that contain cracks, serials, movies and things that are on the legal edge, also try to sneak in some kind of nasty stuff on your Mac while browsing them.
The next advice that I can give you is to use a powerful ad blocker which will prevent a lot of unwanted content from popping up on your screen. Depending on the browser that you're using, you could try AdBlocker Plus, uBlock Origin or AdGuard. Also, you're going to run across websites that ask you to disable your ad blocker; I recommend not doing that unless you can't find similar content anywhere else and you really need that one. Even then, it's better to simply whitelist the website in the blocker instead of disabling the extension completely.
As far as security tools go, the best one I've seen is Malwarebytes. It doesn't only have a great detection rate, but it's also more effective than most when it comes to removing the files that have already managed to infect your Mac. There's also an application called RansomWhere? which is great at dealing with those new attacks that encrypt your important files or the entire computer and ask you for money for the unlock key.
Lastly, though I really don't like using antivirus applications, you might need them from time. According to what I've read, BitDefender (the paid version) is the best one for Macs, but if you don't like spending money, you can always try a free antivirus as there are quite a few of those. However, as I've said before, acting carefully can prevent more attacks and infections than any security solution.