See this code in github, where I’ve implemented zipping DNS messages. A modified q prints the compression rate at the first line. It only shows how much compression you would get when you compress the answer.

For compression we use DEFLATE as described in RFC 1951. A typical example:

q @open.nlnetlabs.nl MX miek.nl
;; Uncompressed/Compressed 253/142 (1.781690)
;; bla bla bla bla

That’s not bad a compression factor of almost 1.8! Some more examples:

# NOERROR
q -dnssec @open.nlnetlabs.nl MX miek.nl
;; Uncompressed/Compressed 612/454 (1.348018)

q -dnssec @ns1.sidn.nl SOA sidn.nl
;; Uncompressed/Compressed 1364/1025 (1.330732)

# NSEC3 NXDOMAIN
q -dnssec @ns1.nic.nl NS miek2.nl
;; Uncompressed/Compressed 1137/922 (1.233189)

# Secure delegation
q -dnssec @ns1.nic.nl NS miek.nl
;; Uncompressed/Compressed 482/339 (1.421829)

# Root server list
q -dnssec @a.root-servers.net NS .
;; Uncompressed/Compressed 1445/459 (3.148148)

So, from this (very) short test you see that you may be able to get an average compression of 33% (factor: 1.5). That’s not that bad… And the beauty is:

There are some bits left in the OPCODE flag.