- REALIQ
- Posts
- Everything You Need to Know About Swap Partition on Linux
Everything You Need to Know About Swap Partition on Linux
And How to Choose the Right Size for Swap

If you’re installing Linux—whether it’s Ubuntu, Linux Mint, Fedora, or any other popular distro—you’ve probably come across the option to create a swap partition. But what exactly is swap space? Do you still need it in 2025? And how much swap should you allocate?
In this blog, I’ll break down everything you actually need to know about swap partitions in a no-nonsense way. By the end, you’ll know whether you even need a swap partition and how to size it properly based on your system and needs.
Table of Contents
What Is Swap Space, Anyway?
Think of swap space as “backup RAM” on your disk.
When your system runs out of physical memory (RAM), it uses swap space to offload inactive memory pages. This helps prevent crashes or freezes when you’ve got too many tabs open or you’re rendering a video while compiling code and running a few VMs at the same time.
There are two types of swap:
Swap Partition – A dedicated section on your disk for swapping.
Swap File – A file stored within your filesystem that serves the same purpose.
Both work similarly, but many modern distros default to using a swap file instead of a separate partition—unless you manually create one during installation.
How to Choose the Right Swap Size
Here’s a simple table that should help:
RAM Size | Recommended Swap (No Hibernation) | Recommended Swap (With Hibernation) |
---|---|---|
Less than 4 GB | 1.5x to 2x RAM | 2x RAM |
4 - 8 GB | 1x RAM | 1.5x RAM |
8 - 16 GB | 2 - 4 GB | Equal to RAM |
16 GB+ | 4 GB | 16 GB |
My Rule of Thumb:
I recommend setting your swap partition size equal to your RAM only if you plan to use hibernation—unless you have more than 16 GB of RAM, then cap it around 16 GB. Otherwise, 4 GB of swap is more than enough for most users.
When You Should Increase Swap:
You use hibernation/suspend-to-disk
You run memory-heavy apps (e.g. VMs, video editing, data science tools)
Your system sometimes freezes or slows with RAM full
When You Can Go Lower (or Use a Swap File Instead):
You have SSD and plenty of RAM (16+ GB)
You're using a desktop and don’t plan to hibernate
You want to resize easily later (swap file is more flexible than a partition)
Bonus Tip: Swap Partition vs Swap File (Which One?)
Swap Partition is more old-school but useful if you like keeping things separated or have specific performance tuning needs.
Swap File is easier to resize later and more flexible. Most distros (Ubuntu, Fedora, Linux Mint) default to this now.
If unsure, go with a small swap file such as 1-2 GB and resize later as needed.
How to Create a Swap File on Linux (Works on All Distros)
Step 1: Create a Swap File (Use dd
for Compatibility)
This creates a 4 GB swap file:
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096 status=progress
You can change count=4096
to any number based on how big you want your swap file. For example, if you want 8 GB you can write 8 × 1024 = 8192, the count is mentioned in MBs.
Step 2: Set Correct Permissions
sudo chmod 600 /swapfile
Step 3: Set Up the File as Swap
sudo mkswap /swapfile
Step 4: Enable the Swap File
sudo swapon /swapfile
Step 5: Make the Swap Permanent
Edit the fstab
file so the swap file is enabled on every boot:
# to acess the fstab file
sudo nano /etc/fstab
# add this line at the bottom of the file
/swapfile none swap sw 0 0
Save and exit (Ctrl+O
, Enter
, then Ctrl+X
in nano).
Step 6: Verify It’s Working
swapon --show
You should now see swap space listed.
To Remove the Swap File (Optional Cleanup)
If you ever want to delete the swap file:
sudo swapoff /swapfile
sudo rm /swapfile
Also remove the /swapfile
line from /etc/fstab
from Step 5.
Final Thoughts: My Personal Take
I’ve installed Linux on countless machines—laptops, desktops, and VMs—and honestly, in 2025, a 4 GB swap file is perfectly fine for most setups unless you have very specific needs.
If you’re going for a custom installation with separating your /home
partition and don’t want to write a few lines of code to manage the swap file, then go ahead and create a swap partition. Otherwise, let the installer handle it with a swap file.
Either way, don’t skip swap altogether. It’s like a seat belt – it doesn’t take much space, and when you need it, you’ll be glad it’s there.
Reply