Take the 2-minute tour ×

Given a gzip compressed file, how do I know what compression level (1-9) was used for it?

share|improve this question

4 Answers 4

up vote 4 down vote accepted

There is no way to directly determine gzip level .
The only way to determine it in my opinion is to gunzip the file and compressing it at different levels and then comparing the results with your existing file size.
I believe the default level is 6 so in most cases that should be your answer

share|improve this answer
I read somewhere that tar -cz defaults to 9. Is that true? –  rabin Apr 12 '11 at 16:37
Yes. GNU tar uses level 9 by default when gzipping. –  Andrew Lambert Apr 12 '11 at 17:26

It is stored in the header of file. To see it, use file command. For example:

$ file testfile.gz
testfile.gz: gzip compressed data, from Unix, last modified: Sun Sep 15 14:22:19 2013, max compression

Unfortunately there are only three possible values in the header: max speed (level 1), max compression (level 9) and "normal" (all other levels). But better than nothing!

share|improve this answer

gzip -l <filename> will give you the compression ratio, but there's no way of directly finding the compression level used.

share|improve this answer

There is no direct way of knowing it. It most probably 6 (the current default) or 9 (the best compression). you need to try and compare.

See http://stackoverflow.com/questions/16153334/how-to-determine-the-compression-level-of-deflate

share|improve this answer

Your Answer


