How TRIM and Garbage Collection Work

Why flash cannot overwrite in place, what TRIM tells the drive, how background garbage collection works, and why deleted data lingers until it is reclaimed.

Ssd housekeeping diagram, photographed for a technology article.

Delete a file from a solid-state drive and the space it used looks free within moments, yet the flash chips inside have not actually erased anything. That gap between marking data gone and physically clearing it explains why an SSD stays quick over years of use, and why a deleted file on flash is far harder to bring back than one from a spinning disk. This piece walks through the housekeeping two features perform, TRIM and garbage collection, and what their behaviour means for speed, wear, and any hope of recovering something removed by mistake.

Why flash cannot change a byte in place

Data on an SSD lives in cells grouped into pages, usually 4 to 16 kilobytes each, and pages are gathered into much larger blocks holding hundreds of pages at a time. Writing and erasing do not happen at the same scale. A page can be programmed only while it is empty, but clearing a single page on its own is impossible. Erasing works on a whole block at once, and that mismatch shapes everything else the controller does.

Because of it, changing stored data is never a plain overwrite. The controller writes the new version to a fresh empty page and marks the old page stale, leaving the previous contents sitting there until the whole block is erased. A block therefore fills with a patchwork of valid and abandoned pages, and the drive needs a way to tidy that mess before it runs short of empty space, a pressure the guide on how flash memory ages examines closely.

What TRIM tells the drive

File deletion is mostly bookkeeping. When you remove a file, the operating system edits its own index to mark those logical addresses as available, but the underlying data is untouched, and for a long time the drive was never informed. The SSD kept believing every one of those stale pages still held something worth preserving, so its housekeeping dragged useless data around for no reason.

TRIM closes that gap. It is a command the operating system sends listing the logical block addresses that no longer contain anything needed. Once the controller receives it, those pages are flagged invalid and can be cleared at the next opportunity. The drive stops wasting effort on dead data, keeps more genuinely free space ready, and avoids the slow decline that early drives suffered as they filled.

Background garbage collection

Garbage collection is the routine that turns half-used blocks back into clean, writable space. The controller selects a block heavy with invalid pages, copies the few pages still holding good data into a fresh block, then erases the original in full so it rejoins the pool of ready space. Much of this runs quietly during idle moments, which is why a drive can feel consistently quick even after months of heavy work.

TRIM and garbage collection operate as a pair. Every page TRIM marks invalid is one the collector no longer has to copy, so cleanup moves less data and finishes sooner. When a drive lacks accurate information about what is free, it copies far more than necessary, and each extra copy counts as real wear, the multiplying effect the explainer on how writes multiply on flash sets out.

The vocabulary in one place

These terms overlap in casual conversation, so it helps to separate what each one actually refers to.

Term What it refers to
Page Smallest unit that can be written, a few kilobytes
Block Group of pages, the smallest unit that can be erased
TRIM Command naming addresses the drive may safely discard
Garbage collection Reclaiming blocks by moving valid pages, then erasing
Stale page Holds old data already rewritten somewhere else

What it means for recovery

On a mechanical hard drive, a deleted file stays on the platter until new data happens to land on the same spot, which is exactly why undelete utilities so often succeed. Flash behaves differently once TRIM is involved. The moment the operating system reports those addresses as free, the controller may erase them during its next housekeeping pass, sometimes within seconds of the deletion.

After that erase there is nothing left to read. Many drives return deterministic zeroes for trimmed addresses, so recovery software sees blank space rather than faint traces. This makes accidental deletion on an SSD far less forgiving, and it is a strong argument for keeping real backups rather than trusting that a slip can be undone, the safeguard the comparison of keeping copies online and at home weighs up.

When TRIM is not active

TRIM is common but never guaranteed. Many USB enclosures and older bridge chips do not pass the command through to the drive inside them, so an SSD in an external caddy may never receive it. Some RAID arrangements historically blocked it, and very old operating systems predate the feature entirely. Certain adapters fall into the same silence without warning.

Without TRIM, the controller has to guess which pages still matter using only its own record of writes, so it keeps shuffling data the system already abandoned. Performance can sag as the drive fills, since less clean space is available at any moment. One side effect is that deleted data survives longer, which occasionally aids recovery but works against the steady speed the drive is meant to deliver. Moving to a roomier disk can reset that pressure, the process the walkthrough on shifting to a bigger drive steps through.

What this means in practice

The two routines exist because flash is fast to read, quick to write into empty space, and slow to erase. TRIM keeps the drive honest about what is genuinely free, and garbage collection uses that knowledge to prepare clean blocks before you need them. Together they hide the awkward erase-before-write cycle so that the drive feels like ordinary storage, even though nothing about it works the way a hard disk does.

For everyday use the sensible response is to leave TRIM enabled, which it is by default on modern systems, and to treat deletion on flash as close to permanent. Keep some free capacity so the collector always has room to work, and rely on backups rather than recovery tools. Those habits let the housekeeping do its job while protecting you from the one behaviour that surprises people most, how completely a removed file can vanish.

Frequently asked questions

What is TRIM?

TRIM is a command the operating system sends to an SSD to say which logical addresses no longer hold needed data, usually after files are deleted. The drive marks those pages invalid so it can erase them during routine housekeeping. Without TRIM the controller keeps treating deleted data as valid, which slows the drive over time and forces it to move more data than necessary.

What is garbage collection on an SSD?

Garbage collection is the drive reclaiming space clogged with outdated pages. Because flash erases in large blocks but writes in small pages, blocks end up mixing valid and stale data. The controller copies the still-valid pages into a fresh block, erases the old block completely, and returns it to the free pool. It runs in the background during idle time to keep writable space ready.

Why can deleted files not be recovered from SSDs?

Once TRIM tells the drive that deleted addresses are free, the controller can erase those blocks within seconds during its next pass. After the erase the cells are blank, and many drives report deterministic zeroes for trimmed regions, so recovery software finds nothing to reconstruct. On a hard drive the data lingers until overwritten, but flash housekeeping removes it far more aggressively, which is why undelete tools rarely help.