Sometimes you can't 100% - like many things in life you just have to be careful and use common sense.
There are many 'rogue' anti-malware programs out there which are viruses themselves - if a download is free, promises the earth and sounds too good to be true - then it probably is - do a google search on the programs name and find out something about it first before downloading.
Don't download free or cracked software from file sharing sites - they are often riddled with viruses and trojans, and avoid surfing porn and sex sites - they will invade your PC with cookies and pop-ups.
Always use a GOOD antivirus suite such as Kaspersky, together with some good anti-spyware programs, such as Windows Defender/Ad-aware/Spybot S&D/SpywareBlaster (use them all together - available free from
HERE)
You will never be 100% secure, but use these programs and your common sense and you will be as safe as you can be