Why can I not compress AND encrypt a folder in Windows?

Just a random bit of knowledge to share here :)

If you open the Advanced Attributes of a folder (right-click on it, choose properties, then click Advanced...), you have the option at the bottom of the window to either compress the contents to save disk space, or encrypt the contents to secure data.

Judging by the check-box options instead of radio buttons, you might think that you can select both options, but you cannot.  Bad UI aside, why is this?

image

According to Wikipedia's article on File Compression (https://en.wikipedia.org/wiki/File_compression):

Lossless compression algorithms usually exploit statistical redundancy in such a way as to represent the sender's data more concisely with fewer errors. Lossless compression is possible because most real-world data has statistical redundancy. For example, in English text, the letter 'e' is much more common than the letter 'z', and the probability that the letter 'q' will be followed by the letter 'z' is very small.

<snip>

However, lossless data compression algorithms will always fail to compress some files; indeed, any compression algorithm will necessarily fail to compress any data containing no discernible patterns. Attempts to compress data that has been compressed already will therefore usually result in an expansion, as will attempts to compress encrypted data.

So... compression algorithms work their magic by finding redundant data, and replacing the redundancy with a smaller bit of data that can be expanded out to represent that redundant data (yes, the word "redundant" was quite redundant in the previous sentence).  However, data that has been encrypted by a good encryption algorithm should be indistinguishable from random data. 

If there are redundant patterns in the encrypted file, the encrypted data may be subject to cryptanalysis techniques such as Frequency Analysis.  The Encrypting File System (EFS) within Windows uses FIPS 140-evaluated Microsoft Cryptographic Service Providers,so your encrypted data is safe.  Attempts to compress this encrypted data would actually cause the file size to INCREASE.  Good times!

Read more about the Encrypting File System and associated best practices here and here.