---
title: "File Compression Algorithms"
source: "https://docs.nexcess.com/hosting/server-administration/file-compression-algorithms/"
description: "What's the difference between `.tar`, `.gz`, and `.tar.gz`? Our guide defines file compression and covers the most popular algorithms on Linux."
vertical: "Hosting"
date: "2025-08-29"
last_modified: "2026-07-29"
---

# File Compression Algorithms

Use compression algorithms to reduce the size of your digital files and folders. The main goals of compression are to **save storage space**, **speed up file transfers**, and **simplify file organization** by bundling multiple files or folders into one archive.

In practice, compression allows you to:

- Store more data on the same disk.
- Transfer files faster over networks.
- Organize multiple files, and/or folders into a single, portable package.
- Preserve file attributes like permissions and ownership (when using archive tools like TAR)

## Parameters / Features

| **Format** | **Purpose** | **Compression** | **Common OS** | **Notes** |
|---|---|---|---|---|
| **TAR** | Bundles multiple files | None | Linux/Unix | No size reduction; often used before compression |
| **Gzip (.gz)** | Compresses single files | Yes (Gzip) | Linux/Unix | Uses DEFLATE algorithm |
| **TAR.GZ / TGZ** | Bundles + compresses | Yes (Gzip) | Linux/Unix | Common for backups |
| **ZIP** | Bundles + compresses | Yes | Windows, Linux, Mac | Widely supported |
| **BZ2 (.bz2)** | Compresses single files | Yes (Bzip2) | Linux/Unix | Better compression than Gzip but slower |

## Examples

**TAR:**

```
<strong>tar -cvf archive.tar my_folder</strong>
```

- **Creates an archive with no compression.

**Gzip:**

```
<strong>gzip file.txt</strong>
```

- **Compresses file.txt into file.txt.gz.

**TAR.GZ:**

```
<strong>tar -czvf archive.tar.gz my_folder</strong>
```

- **Bundles and compresses a folder into one file.

**ZIP:**

```
<strong>zip -r archive.zip my_folder</strong>
```

- **Creates a compressed zip archive.

**Bzip2:**

```
<strong>bzip2 file.txt</strong>
```

- **Compresses a file with better ratios than Gzip.**

## Common Use Cases

- **Backups: Archiving folders into .tar.gz or .tgz files.
- **Cross-platform sharing: Using .zip for compatibility across Windows, macOS, and Linux.
- **Disk space savings: Compressing large log files with Gzip or Bzip2.
- **Data transfer efficiency: Sending compressed files over the internet to reduce upload/download times.**

## Reference Links

How to Use Tar, GZIP, & Zip in Linux

[https://man7.org/linux/man-pages/man1/tar.1.html](https://man7.org/linux/man-pages/man1/tar.1.html)

[https://www.gnu.org/software/gzip/manual/gzip.html](https://www.gnu.org/software/gzip/manual/gzip.html)
