Why Linux is virus free while Windows is not ?
Have you ever wandered why Windows,Android may get affected by virus while Linux/Mac does not ?
There are three factors.
1) The likelihood of users to run or be exposed to malware.
2) The ability for that malware to escalate and take ownership of the system
3) The likelihood of malware being created for that platform.
1) Any system which runs unsigned applications means that users can unwittingly infect their computers with malware. OS X, Windows, Android all let users do this. But iOS does not. Out of the box, Mac systems have a preference set which limits them to only signed apps from the MAS.
2) The user accounts on Unix systems don't have administration priveleges which makes that applications running at user level cannot change system files. However security loopholes exist on all systems which allow escalation of privileges.
On the Mac, Sandboxing and Address Space Randomization are technologies which prevent such escalation. Sandboxing limits the priveledges of each thread. Address space randomization makes it hard for a buffer-over-run to target system memory.
Flash and Java punch big holes in Mac security and so should not be installed if you want to avoid malware.
In the XP days Windows did not do very much to prevent malware from embedding itself into the system. Newer versions of Windows are much better. But the broad diversity of Windows hardware means a plethora of drivers and plug ins from many sources. This presents the malware writer with a bigger target.
Bizarrely, Microsoft has often left malware detection and removal to after-market products. This seems to be a reckless way to treat customers.
3) The biggest difference is the community of malware developers is very much a WinTel-based operation. This community has developed and maintained a box of malware tools which are built around Windows. This is the principal reason why users running Windows users have to endure so many problems. When this malware industry was being built, the Mac was unaffordable for such hackers and not a particularly worthwhile target.
The most secure system right now is one where the OS is limited to running approved signed applications, and where those applications sit in a sandbox.
In terms of the likelihood of infection...
(un-jailbroken) iOS is clearly the most secure option
The Mac if left with the default settings and with Java and Flash uninstalled is also pretty good.
Windows is okay if running on vanilla hardware with a minimal install. But becomes more vulnerable after being filled with shovelware.
For the reasons above, Windows and Android are much more likely to suffer malware.