For a long while a very significant difference is that OS X (as it was called) had full Unix style protection of the system, most of the OS was protected, and loaded applications could not gain access to the system files and settings.
Windows for the longest time allowed applications full access to the file system, which gave malware a bit of an easy target. With Vista onwards, Windows has improved its security model.
At the present time, both MacOS and Windows have a large set of security features which make it more difficult for malware to gain control of the system.
There are a bunch of technologies on both platforms which should make it impossible to gain control, but in reality occasionally expose vulnerabilities.
In terms of engineering, there isn’t a vast gulf between the two platforms. Security is like an arms race, it requires constant and repeated innovation to keep safe.
But the average Mac user is far less likely to encounter a problem because of other reasons.
- A lot of the Mac is actually open source software, while Windows is closed source. Security flaws in open software can be found and fixed by the global community.
- The Mac comes out of the box requiring all apps to be signed.
- The Mac comes out of the box without Flash or Java installed, these subsystems are major causes of malware issues.
- Many Mac users stick to the App store for their software, and apps delivered that way are sandboxed. So even if there is malware running, it can’t get at the file-system.
- The Mac user rarely has to do system maintenance, install third party drivers and so on. Because the average PC usually comes with a bunch of parts from multiple vendors, the user will end up installing drivers from all over the place.
- And the most important reason is that the global malware industry grew up on the PC. All their tools and all their methodologies are about Windows. So even if there is a glaring security hole on the Mac, it often goes unexploited because the community which exploits this stuff has 20 years of investment in the Windows platform.