How to Defragment a Mac, and Why Modern Macs Don't Need It
No, a Mac with an SSD and APFS does not need defragmenting, and you should not run a third-party defrag tool on it. There is no defragment button in Disk Utility because macOS manages file layout itself, and on flash storage the scattered blocks that defragmentation tidies up do not slow anything down.
Most people who search "how to defragment mac" are really asking why the Mac feels slow or why the disk keeps filling up. Both have real causes and real fixes, and neither involves rearranging blocks. This guide explains why defragmentation stopped mattering, the one case where an old spinning drive still benefits from a fresh layout, and what to do instead.
What defragmentation was for
Apple's old support note About disk optimization with Mac OS X, now archived, defines optimization as rearranging files and metadata "to improve data access times and minimize time moving a hard drive's head." A fragmented file on a spinning disk is stored in pieces at different locations, so the head has to travel between them, and each trip costs time.
Even in the hard-drive era, that note said "You probably won't need to optimize at all if you use Mac OS X." Its reasons were specific to Mac OS Extended (HFS Plus): the file system avoids reusing small gaps left by deleted files, delayed allocation combines many small writes into one larger allocation, and Mac OS X 10.3 and later "can also automatically defragment" slow-growing files, a process Apple called Hot File Adaptive Clustering. The note also warned that a power loss during optimization could damage files, and that moving the files macOS places in its fast startup area could make performance worse.
So the Mac never had a defrag habit to lose. It was already doing the part that mattered on its own.
Why an SSD does not care about fragmentation
The whole cost of fragmentation on a hard drive is the head moving across a spinning platter. An SSD has no head and no platter. It reads flash memory electronically, and reaching a block in one place takes about as long as reaching a block somewhere else, so a file in ten pieces reads almost as fast as a file in one.
Rewriting every file to make it contiguous therefore buys nothing on an SSD, and it spends write cycles to do it. Flash cells wear with writes, and a full-disk defrag pass is one of the largest write workloads you can deliberately create.
What an SSD does need is to know which blocks are free, so it can prepare them ahead of the next write. That is the job of TRIM: macOS tells the drive which blocks no longer hold file data. Apple's internal SSDs receive TRIM commands by default. You can confirm it in System Information (in Applications › Utilities): select NVMExpress or SATA under Hardware, then look for TRIM Support: Yes on the internal drive. You can also check whether a disk is an SSD in Terminal:
diskutil info / | grep "Solid State"
TRIM and trimforce for third-party SSDs
If you replaced the drive in an older Mac with a third-party SATA SSD, System Information may show TRIM Support: No. The trimforce command exists for that case. Its manual page (run man trimforce in Terminal) says it "enables sending TRIM commands to third-party drives attached to an AHCI controller," that "By default, TRIM commands are not sent to third-party drives," and that you should "Use extreme caution when enabling TRIM, as some drives may not correctly handle the commands." It needs an administrator and a restart.
sudo trimforce enable
Before you run it, check that the drive maker documents TRIM support on macOS, and have a current backup. If something goes wrong afterwards, sudo trimforce disable and a restart stop the commands again. Do not run it on a Mac that already reports TRIM Support: Yes; there is nothing to gain.
What APFS changes: copy-on-write and snapshots
Since macOS High Sierra 10.13, Macs use APFS. Apple's file system formats guide says APFS "is optimized for the Flash/SSD storage used in recent Mac computers" and lists snapshots and space sharing among its features. The Apple File System Reference describes "the copy-on-write approach to modifying objects": changed data is written to new blocks rather than overwriting the old ones in place, which is part of how APFS survives a crash.
Copy-on-write is the reason a classic defragmenter is a poor fit. A tool that "moves" a file to make it contiguous is really writing a new copy of its blocks. If a Time Machine local snapshot still references the old blocks, those blocks stay allocated until the snapshot goes away, so the pass can use space instead of saving it. Apple notes that Time Machine saves a local snapshot about every hour and deletes snapshots as they age or as space is needed, which is normal and not something to fight.
APFS also has its own defragmentation feature for user data, managed by macOS rather than by an app. The diskutil manual page lists a defragment verb that can "Manage automatic background defragmentation of user file data at the APFS Container or Volume level." You can read the current state without changing anything:
diskutil apfs defragment / status
On an Apple Silicon MacBook's internal SSD, the volume and its container both report that defragmentation is disabled. That is the expected state for flash storage, not a missing setting to switch on. The enable form changes the disk's configuration, so leave it alone unless you have a specific reason on a hard drive.
What people actually feel when they search "defrag"
The symptom behind the search is usually one of two things.
The Mac feels slow. On a modern Mac, slowness almost always has a cause you can see: one process using a full CPU core, memory pressure staying yellow or red, thermal throttling, or Spotlight indexing after an update. Why is my Mac so slow walks through finding which of those it is in Activity Monitor, and how to speed up a Mac covers the changes that make a measurable difference. Block layout is not on either list.
The disk is nearly full. This is the one that does affect speed. macOS needs free space for swap, updates, caches and snapshots, and a startup disk with only a few gigabytes left will feel sluggish and show warnings. Freeing space helps far more than any rearrangement of what remains. Mac startup disk full explains how to measure where the space went before deleting anything.
If you suspect the disk itself rather than its contents, for example after crashes, errors when saving, or a drive that will not mount, Disk Utility's First Aid checks the file system structure and repairs what it can. That is the closest thing to "disk maintenance" macOS asks of you. The steps, including running it from macOS Recovery for the startup disk, are in how to use Disk Utility First Aid.
Old iMacs and external hard drives
A spinning hard drive, in an older iMac or Mac mini or in an external USB enclosure, is the one case where fragmentation can still be felt. Apple's archived note describes the situation: "If your disks are almost full, and you often modify or create large files (such as editing video)... there's a chance the disks could be fragmented."
Its first suggestion was simply "Try restarting first." Its second option is the one that still holds up today: "back up your important files, erase the hard disk," then put the system and your files back. A fresh restore writes every file in one pass onto an empty disk, so it lands in large contiguous runs, and you finish with a verified backup.
- Back up the drive with Time Machine or another backup you have tested by restoring a file from it.
- Erase the drive in Disk Utility, following Apple's erase and reformat guide. For a startup disk this happens from macOS Recovery.
- Reinstall macOS if it was the startup disk, then restore your files from the backup.
Before you go to that trouble, make sure the drive has free space afterwards. A hard drive that is 95% full will fragment again quickly, and a drive that makes clicking noises or shows errors in First Aid needs replacing, not rearranging. For an old Mac still running from a hard drive, moving to an SSD changes far more than any layout work can.
Why to be skeptical of "defrag" apps for Mac
A utility that offers to defragment an SSD-based Mac is selling a fix for a cost that does not exist on that hardware. The progress bar and the before-and-after map look convincing, but the result is extra writes to flash, possible space held by snapshots, and in the worst case the power-loss risk Apple described.
Be wary of tools that ask for broad disk access to "optimize" a volume, that do not say which file system they support, or that make defragmentation sound like routine maintenance. If a tool's own documentation does not explain how it handles APFS snapshots and copy-on-write, assume it was designed for something else. Disk Utility's First Aid, a backup, and enough free space cover what a Mac's disk actually needs.
Where Mole fits
Mole does not defragment disks, and it will not. On an SSD there is nothing to gain, and on APFS the layout belongs to macOS. Mole stays on the parts of the problem you can see: Clean reviews caches, logs, uninstalled-app leftovers, local Time Machine snapshots and the Trash before anything is removed, and Analyze draws a treemap of the disk so you can drill into the largest folders.
When you are not sure the disk is the issue at all, the Status dashboard shows CPU, Memory, Disk and the processes using the most resources, updating every second. Mole's Doctor also flags startup disk usage above 90%, because macOS needs free space for swap files, snapshots and updates. The Mole help page lists what each check means.
FAQ
Does a MacBook with an SSD need defragmenting?
No. Fragmentation costs time only when a drive head has to move between pieces of a file, and an SSD has no moving parts. Defragmenting it adds writes without making reads faster.
Is there a built-in defrag tool on Mac?
Disk Utility has no defragment button. APFS has an automatic background defragmentation feature managed through diskutil apfs defragment, and on internal SSDs it is normally disabled, which is the intended state.
Should I defragment an external hard drive on my Mac?
Usually not. If a nearly full hard drive that holds large, often-changed files has become slow, back it up, erase it and restore the files, which also leaves you with a tested backup.
Can Mole defragment my Mac?
No. Mole does not defragment disks. It helps you free space with Clean and Analyze and see what is running in Status.