TechKnowSurge
CompTIA Tech+ 2.5 CompTIA A+ Core 1 3.3 CompTIA A+ Core 2 1.3 CompTIA Server+ 4.3
VideoComputeFree

Fragmentation and Defragmenting

File fragmentation occurs when data is stored across non-contiguous clusters on a storage device, which can degrade performance and shorten the lifespan of mechanical hard drives. Defragmentation consolidates scattered file clusters and is recommended for HDDs but should not be run on solid-state drives or optical media.

Complete this video to capture a CTF flag worth 1 point.

About this video

Storage devices organize data in units called clusters, and a single file may be written across many clusters that are scattered throughout the drive rather than grouped together. This condition — fragmentation — develops naturally as files are created, modified, and deleted over time, leaving gaps that the operating system fills with portions of other files. Tools such as DiskView can visualize cluster allocation across a drive, marking fragmented file clusters so technicians can assess the degree of fragmentation present. On magnetic hard disk drives, fragmentation carries real performance and hardware consequences. The drive's read/write arm must physically seek to each discontiguous cluster location, and the platter must spin to bring each section under the head. This repeated mechanical movement not only slows data retrieval but also increases wear on the drive's bearings and moving components, gradually degrading both speed and lifespan. Defragmentation addresses this by rewriting scattered file data into adjacent cluster sequences, reducing the physical work required to read any given file. Not all storage technologies benefit from defragmentation, and applying it indiscriminately can cause harm. Solid-state drives use flash memory with no moving parts, so access time is not affected by whether clusters are contiguous or scattered. Running defragmentation on an SSD generates unnecessary write operations that consume the drive's finite write endurance without providing any performance gain. Optical formats such as CD-ROM are written once and finalized — a process that records a file location table and closes the disc to further writing — making them inherently incompatible with any defragmentation process. Windows automatically identifies drive types and applies the appropriate optimization routine, performing defragmentation only on HDDs while using alternative optimization methods for SSDs.

What you'll learn

What's covered

Fragmentation & Storage

Aligned to

CompTIA Tech+
2.5 Compare and contrast storage types.
CompTIA A+ Core 1
3.3 Given a scenario, select and install storage devices.
CompTIA A+ Core 2
1.3 Given a scenario, use features and tools of the Microsoft Windows 10/11 operating system (OS).
CompTIA Server+
4.3 Given a scenario, troubleshoot storage problems.

Key terms

Fragmentation
The process of breaking a packet into smaller pieces when its size exceeds the maximum transmission unit of a network link, with reassembly occurring at the destination.
Defragmentation
The process of consolidating fragmented files on a storage device by rewriting them into contiguous clusters to improve access speed and reduce mechanical wear.
Hard Disk Drive
HDD
A traditional storage device that uses rotating magnetic platters and read/write heads to store and retrieve data persistently. HDDs offer high-capacity storage at lower cost per gigabyte than SSDs, but with slower speeds and moving mechanical parts.
Solid State Drive
SSD
A storage device that uses flash memory chips with no moving mechanical parts to store data persistently, offering faster read/write speeds, lower latency, and greater durability than traditional hard disk drives. SSDs connect via SATA, NVMe, or M.2 interfaces.
Cluster
The smallest unit of disk space that a file system allocates when storing data; a file occupies at least one cluster even if it is smaller, with common cluster sizes of 4,096 bytes.
Optical Media
Storage media, such as CDs and DVDs, that uses laser light reflected off a disc surface to store and read binary data.

Topics

File Fragmentation Defragmentation Hdd Ssd Storage Management File Systems

Transcript

Our data gets saved in clusters, and a single file could take up many different clusters, and those clusters don't even need to be next to each other. We call that fragmentation, and it can cause some problems.

What fragmentation looks like

Let's say we have a saved file in 11, 12, 13, 14 and 15, so 11, 12, 13, 14 and 15. It takes up all of these clusters right here. But then we go and we save a second file. We're going to call this file two, and so it's taking up, let's say, 16, 17, 21, 22 and 23.

Now, when we go and save more changes to this file right here that needs more clusters, what's going to happen is it's going to start saving in the next available clusters. And now what we've just done is we've created fragmented files.

Fragmentation is when a file is split amongst clusters that aren't right next to each other. So in this case right here, we've got file one that takes up five clusters right here, then we have file two, and now we have file one again. So since the file is split amongst these clusters, file one is now fragmented.

Seeing fragmentation on a drive

I used my DiskView 64 program to map out the clusters of this drive, and so we can see there's some color coding involved. What I can do is I can go to the Help menu and say Legends to see what the different colors mean, and it actually points out fragmented file clusters, and that's in red.

So what I'm going to do is I'm going to look, and I can see that there are these — let me turn off the highlighter here — we've got these little red dots sprinkled throughout here. So these are the different files that we see, and when you click on them you can see them highlighting different sections. So this file has some clusters here, some clusters here, some clusters here, some clusters here.

I'm going to double click on this to open it up, and we can see a list of all of it. So in total it has 185 clusters that this takes up, but you can see that they're — we call this discontiguous — they're not contiguous, which means they're not in sequence with each other. So here are the different ranges here, and you can see that it's quite a bit broken up into all of these. So this is what's considered a fragmented file.

Why fragmentation is a problem

When we access a file, what's going to happen is it's going to take all of the clusters that have that file in it, assemble it together and put it into the RAM, and then we have access to it.

This can be problematic if we're talking about magnetic storage. With magnetic storage, for instance this hard disk drive, what has to happen is that the spindle turns in order to access different parts of this disc, and then we have this arm that goes back and forth and reads the data on that disc. Now if it's all contiguous, that means the clusters are all lined up, then this arm spins to that location, the spindle spins around, it then loads, brings it into RAM, and now we have access to it. However, if it's in different parts of this disc, then this arm has to go and find those different parts and read the data to put it all together.

Now this causes two problems. Number one, there's a lot of extra searching that happens with this, so it slows the access that we have to that data; it takes a lot longer for it to access all of that data. The other problem is that this device has bearings to it, there's physical movement of it, and over time those parts wear out and we wear them down and this device slows down. So by putting all that extra effort into reading all that data and finding it on different spots of this disc, we're actually reducing the lifespan of this, and this whole drive will slow over time and it will get slower and slower as we're trying to access the data on this device.

Defragmenting

Because this can cause problems on some storage devices, there is a process called defragmenting, or defrag. You do a defrag on something like a hard disk drive. What that means is what it'll do is it'll start consolidating these fragmented files into contiguous clusters. And so what that means is that it will rewrite this file one into a different spot on the drive, and then it will remove it from this spot right here. So now we have it all contiguous; it's all in clusters that are in a row on this storage device.

On Windows devices, if I click on the start button and type in defrag or defragment, here pops up Optimize Drives, and it shows the different drives on here and when it's gone through its last routine.

Solid state drives

Now, I specifically said defragmentation is a problem on hard disk drives, and we wouldn't necessarily want to have that same process happen on solid state drives. So it knows that this is a solid state drive, and it performs other drive optimization on the solid state drive. But if there was a hard disk drive, then on here we could actually go through the process of defragmenting.

Solid state drives are a different technology, and the way it works works very different. There's no moving parts on this, it's not mechanical, and so it really doesn't matter too much about fragmented files on something like a solid state drive. So we wouldn't really want to run a fragmentation process on a solid state drive, because it doesn't really do anything for us, and then what it would do is it would just put extra load on this device. And these devices can wear out over time as well, so we wouldn't want to go through the process of reducing the lifespan of these devices. So you wouldn't run defragmenting on a solid state device.

CD-ROM

CD-ROM technology is a little different. CD stands for compact disc; this is a small disc format. And then ROM stands for read-only memory, which is primarily what CD-ROMs are used for, is for read-only memory, that it has a burned-on image, which means that it doesn't really change, that it's something that's incorporated into it.

There are some writable discs, and with those writable discs, typically what we do with it is we write the files onto the disc, and then once we're done writing the files on the disc we will finalize, we'll do a finalization, and then you can't really write onto the disc after that. That finalization just creates kind of like a file location table where it just tells you what's on the CD, and that's the last step of burning a CD.

There are actually rewritable discs where you can change the information that's on the disc, but those are a little more rare, and it has a very limited lifespan of how much you can actually do that onto these discs.

So ultimately, I guess where I'm going with this is, you wouldn't really need to do a defrag on the disc. Typically what you do on compact discs is you just burn the image or whatever it is onto the disc, and then that's the format, that's what's on it, and from then on it's read-only memory.

About TechKnowSurge

TechKnowSurge builds IT and cybersecurity professionals through hands-on, concept-first training built around real understanding — not memorization. Free interactive tools, structured programs, and 25+ years of real-world experience, all in one place.

Explore free tools and programs →