Guides

How to compress files with 7-Zip: GUI, command line and maximum compression settings

Compress files using 7-Zip on Windows and Linux: Add to archive, 7z a -mx=9, the settings that maximize compression, passwords with -mhe and split archives.

Published ~8 min read
On this page

Short answer: in Windows, right-click the files, choose 7-Zip, Add to archive..., pick 7z as the format and Ultra as the level, then click OK. On the command line the same is 7z a -t7z -mx=9 archive.7z folder/; on Debian 12 the command is called 7zz.

Windows (cmd) · Linux
"C:\Program Files\7-Zip\7z.exe" a -t7z -mx=9 backup.7z C:\data\project\
7z a -t7z -mx=9 backup.7z project/          # Debian 13, Ubuntu 24.04 and newer
7zz a -t7z -mx=9 backup.7z project/         # Debian 12 with the 7zip package

Everything below is taken from the 7-Zip 26.06 manual (the current release on 7-zip.org, dated 2026-11-06) and the package lists of Debian and Ubuntu, read on 13.11.2026. 7-Zip is not installed on our server, so no compression ratios on this page are measured by us; the numbers are the documented defaults.

Install 7-Zip on Windows and Linux

On Windows, download the installer from 7-zip.org (x64, ARM64 and 32-bit builds). It adds the 7-Zip entries to the Explorer context menu and puts the console program 7z.exe in the install folder, which is not on the PATH by default, so either type the full path or add the folder to PATH yourself.

On Linux the package names changed. The old p7zip port stopped at version 16.02, and the 7-Zip readme calls it outdated; the current code comes from the 7zip package:

ReleaseInstallVersionCommand
Debian 12 (bookworm)sudo apt install 7zip26.02 (packaged as 22.01+really26.02)7zz only; p7zip-full still gives 7z
Debian 13 (trixie)sudo apt install 7zip25.017z, 7za, 7zr; p7zip-full is now a transitional package
Ubuntu 24.04 (noble)sudo apt install 7zip23.017z, 7za, 7zr; p7zip-full is transitional
Ubuntu 26.04 (resolute)sudo apt install 7zip26.007z, 7za, 7zr
Any distributionTarball from 7-zip.org26.067zz (and the static 7zzs)

Run command -v 7z 7zz after installing to see which name you got. The 7-Zip readme calls the command line syntax of these programs similar and says you can use 7zz, 7za or 7zr wherever the manual writes 7z; 7za and 7zr handle fewer formats. Note that 7-Zip 24.09 raised the default dictionary sizes (Normal from 16 MB to 32 MB, Ultra from 64 MB to 256 MB), so -mx=5 on Ubuntu 24.04's 23.01 uses a smaller dictionary than the table further down.

Compress files in the Windows GUI

  1. 1Select and right-click

    Select the files or folder in Explorer, right-click and choose 7-Zip, Add to archive.... If 7-Zip is missing from the short Windows 11 menu, open Show more options first.

  2. 2Pick format and level

    Archive format: 7z for the best ratio, zip when the recipient has no 7-Zip. Compression level: Store, Fastest, Fast, Normal, Maximum or Ultra. Compression method: leave LZMA2, the default for 7z.

  3. 3Optional: password and splitting

    Under Encryption enter a password and tick Encrypt file names. In Split to volumes type a size such as 1g (the help lists b, k, m and g as units) if the file has to fit a size limit.

  4. 4Check the result

    Right-click the new archive, 7-Zip, Test archive. It reads every file back and reports errors before you delete the originals.

The dialog also shows how much memory compressing and decompressing will need with the settings you picked. Watch the second number if someone with a small machine has to open the archive; for LZMA it is close to the dictionary size.

The command line: a, l, t, x

Linux (use 7z.exe on Windows, 7zz on Debian 12)
7z a archive.7z project/            # add: creates archive.7z, folder name kept inside
7z a archive.zip ./project/*        # zip by extension, without the project/ prefix
7z l archive.7z                     # list contents
7z t archive.7z                     # test integrity
7z x archive.7z -o/tmp/restore      # extract with full paths into /tmp/restore

Without -t, 7-Zip picks the format from the file extension, and a name with no extension becomes a 7z archive. The exit code tells a script what happened: 0 no error, 1 warning (for example a locked file that was skipped), 2 fatal error, 7 command line error, 8 not enough memory. Quote wildcards ("*.txt") if you want 7-Zip's own matcher instead of the shell's; 7-Zip treats *.* as "names with an extension", so use * for everything.

Settings that change the compression ratio

For the 7z format the manual lists what each level sets. All levels from 1 up use LZMA2; level 9 adds the BCJ2 filter for x86 executables:

LevelSwitchDictionaryDefault solid blockTrade-off
Store-mx=0nonenoneNo compression; right for JPEG, MP4 or files that are already archives
Fastest-mx=1256 KB64 MBFast, larger output
Fast-mx=34 MB1 GBGood for large logs when time matters
Normal (default)-mx=532 MB8 GBThe balanced choice
Maximum-mx=7128 MB16 GBSlower, needs more RAM
Ultra-mx=9256 MB16 GBSlowest; decompressing needs about 256 MB of RAM
  • Format: 7z with LZMA2 compresses better than zip with Deflate, whose dictionary is fixed at 32 KB. Zip is the format everyone can open without extra software.
  • Dictionary (-md): how far back the compressor looks for repeats. A bigger dictionary helps only when the data is bigger than the dictionary and contains repeats; for decompression you need about as much RAM as the dictionary.
  • Solid mode (-ms): on by default for 7z. Files are compressed as one stream, so many similar small files shrink a lot. The cost: extracting one file means decompressing its solid block from the start, and damage loses the whole block. -ms=off or a limit such as -ms=1g trades ratio for safety and speed.
  • Threads (-mmt): LZMA2 splits data into chunks to use more threads, and the GUI help says the best LZMA2 ratio comes from 1 or 2 threads. More threads are faster and cost a little ratio.
  • Sort by type (-mqs): groups files by extension in solid archives. The 7-Zip FAQ suggests it when similar files sit in different folders.

How to maximize compression in 7-Zip

maximum ratio, slow
7z a -t7z -m0=lzma2 -mx=9 -md=1g -ms=on -mqs -mmt=2 max.7z data/

This raises the dictionary to 1 GB (the 64-bit limit is 3840 MB), keeps one large solid block, sorts by type and limits LZMA2 to two threads. Whoever extracts it needs about 1 GB of free RAM. Expect the gain over plain -mx=9 to be small or zero unless the data set is several gigabytes of similar files; text, SQL dumps and logs gain the most, already compressed media gains nothing.

Password-protected archives: -p and -mhe

encrypt data and file names
7z a -p -mhe=on secret.7z secret/      # prompts for the password, AES-256
7z a -p -tzip -mem=AES256 secret.zip secret/

-p without a value asks for the password, so it does not end up in your shell history. In 7z archives -p alone encrypts the file contents only; names, sizes and dates stay readable until you add -mhe=on. Zip archives cannot hide file names at all, and the zip default method is the old ZipCrypto, so set -mem=AES256 if you must use zip. The plain zip tool's weaker -e option is covered in the zip command guide.

Split an archive into parts: -v

1 GB parts
7z a -v1g backup.7z data/      # writes backup.7z.001, backup.7z.002, ...
7z x backup.7z.001             # extract: point at the first part, all parts in one folder

Sizes take b, k, m or g (binary units). The manual warns not to copy volumes before archiving has finished, because 7-Zip can still change any volume, the first one included, at the very end.

Compress a backup on a Linux server before copying it off

On a VPS or dedicated server, compress backups before you move them: fewer bytes cross the network and the copy finishes sooner. Two rules make the archive safe to restore:

  • Pack with tar first. tar records Linux owners, groups and permissions; compress the tar stream with 7-Zip. 7-Zip's own manual says to create a tar first for single-file formats like xz and gzip.
  • Test before you delete. Run 7z t on the server, then copy the archive with scp or rsync and keep it on another machine.
Debian 13 · Ubuntu 24.04+ (7zz on Debian 12)
tar -cf - /var/www | 7z a -mx=7 -siwww.tar /root/www-$(date +%F).tar.7z
7z t /root/www-$(date +%F).tar.7z
rsync -av /root/www-*.tar.7z USER@BACKUP_HOST:/backups/

-si reads the data from standard input and stores it under the name you write right after it, here www.tar. To restore, 7z x the archive and unpack the tar as shown in extracting tar files. Keep an eye on RAM: -mx=9 on a small VPS can take a large share of memory, and 7-Zip by default allows itself up to 80 % of RAM when compressing. If you want the archive to open on any machine without 7-Zip, plain tar.gz is the safer format.

Frequently asked

How do I compress files using 7-Zip?

In Windows Explorer, select the files, right-click, choose 7-Zip and then Add to archive, pick the 7z format and a compression level, and click OK. On the command line, 7z a archive.7z folder/ does the same with the default Normal level. On Debian 12 the command from the 7zip package is called 7zz.

What are the best 7-Zip settings for maximum compression?

Use the 7z format with LZMA2 and the Ultra level (-mx=9), which sets a 256 MB dictionary and solid mode. For large sets of similar files, a bigger dictionary such as -md=1g, sorting by type with -mqs and only one or two threads can shrink the archive a little more. Each step makes compression slower and needs more RAM, and decompression needs about as much RAM as the dictionary.

How do I make a password-protected 7z archive that hides file names?

Run 7z a -p -mhe=on secret.7z folder/ and type the password when asked; in the GUI, enter the password and tick Encrypt file names. Without -mhe, 7-Zip encrypts the file contents but leaves names, sizes and dates readable. 7z archives always use AES-256; zip archives cannot hide file names.

Should I install p7zip-full or 7zip on Ubuntu or Debian?

Install 7zip. p7zip is an older port that stopped at 16.02, and on Debian 13 and Ubuntu 24.04 p7zip-full is only a transitional package that pulls in 7zip. On those releases the 7zip package provides the 7z, 7za and 7zr commands; on Debian 12 it provides 7zz.

Related articles

All guides