How to Set Dictionary Size in 7-Zip CLI

This guide explains how to configure the dictionary size when creating archives using the 7-Zip Command Line Interface (CLI). By using the -md switch, you can control the balance between the compression ratio and system memory usage. Below, you will find the exact syntax, supported parameters, and practical command examples to optimize your compression workflows.

The Dictionary Size Switch: -md

In the 7-Zip CLI, the -md switch is used to specify the dictionary size for algorithms like LZMA and LZMA2. A larger dictionary size allows the algorithm to find patterns across larger spans of data, significantly improving the compression ratio for large files at the cost of requiring more RAM during both compression and decompression.

Syntax

The switch uses the following format:

-md={Size}[b|k|m|g]

  • b: Bytes
  • k: Kilobytes
  • m: Megabytes (default unit if omitted in most builds)
  • g: Gigabytes

Alternatively, it can be passed without the equal sign, such as -md64m.

Practical Examples

1. Basic Compression with a 64 MB Dictionary

To compress a folder named data into an archive called archive.7z with a 64 MB dictionary size:

7z a -t7z archive.7z ./data -md=64m

2. Maximum Compression with a 128 MB Dictionary

To pair the dictionary size switch with ultra compression settings (-mx=9):

7z a archive.7z ./data -mx=9 -md=128m

3. Setting via Method Switch (-m)

You can also define the dictionary size directly inside the method configuration switch (-m0):

7z a archive.7z ./data -m0=lzma2:d=64m

Memory Requirements and Considerations

Before increasing the dictionary size, consider the following hardware requirements:

  • Compression Memory: Compressing data typically requires roughly 10 to 11 times the dictionary size in available RAM for LZMA/LZMA2.
  • Decompression Memory: Decompressing the resulting archive requires roughly equal to the dictionary size used during compression. If the dictionary is set too high (such as 1 GB or higher), systems with limited memory may fail to unpack the archive.