Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 5 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
Python also defaults to a compression level on 9: – RFox Feb 15 at 14:28

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
This is the best answer. – Florin Andrei Sep 11 '15 at 20:05
Looks like the rest of a compressed file isn't any clearer. Test-compressing a 201 bytes file with all levels resulted in only 4 different outputs - partitioned by levels as (1,23,45678,9) - with levels 1 and 9 specifically marked (see XFL in RFC1952; that's why file can recognise those). A 10^7 bytes file still only resulted in 7 unique outputs - partitioned (1,2,3,4,5678,9). While this doesn't mean different levels are useless for bigger files, it shows you can't assume 9 unique outputs. – valid Nov 10 '15 at 3:38

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
While the assertion about elvel is false, the command is useful for comrpession ratio. – mveroone Oct 19 '15 at 13:04

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.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.