Is defragmenting an SSD drive a bad idea? I have heard that defragmenting SSD drives will shorten the life span of a drive. Just wondering if there is any truth to this and if so could someone elaborate as to why this happens.
Your best bet is to not "defragment" SSD storage.

Eventually, SSD will lose capacity slowly and gracefully as the controller can’t write the data correctly to exhausted cells, but the repair data from 2011 through 2018 shows that Apple SSD are orders of magnitude more reliable and have longer life than HDD storage currently or in the past could achieve. 


What happens at the user/OS level when an SSD finally wears out?


The life span of the drive is a function of how the controller decides to write data and how much of the capacity is held in reserve to hide small errors over time. An SSD in general will wear out due to write exhaustion before a hard drive will as the magnetic media can withstand several orders of magnitude more writes than SSD memory cells. So the life span is basically set, and defragmentation means more writes than are needed and may in practice increase the chance your storage will degrade before something else causes you to stop using it, Granted, most people are not going to wear out their SSD - especially when you consider the warranties for OEM parts are often longer than one year / three years in the case of AppleCare - but reducing things that can cause thousands (or millions) of unnecessary erase and re-write operations is prudent advice.

But it gets worse for defragmentation than simply adding wear to the memory.

Since an SSD has no moving parts, retrieving a block of data has no penalty due to one block being stored on one chip versus another. The distance electrically to all the data is basically a constant. This is not true for a traditional magnetic drive with spinning platters and a movable read head.

On a spinning drive, the distance between two blocks is affected by head armature movement, rotational timing and cache status. Retrieval time is not at all constant, so "fragmentation" has a performance impact on traditional hard drives due to the mechanical nature of the storage.

Furthermore, SSD controllers selectively manage storage so defragmentation is not only unlikely to speed things up, might actually act counter to the normal storage prediction algorithms, and slow down access since the controller decides where to store data using the extra overhead. Since the device cannot erase just a block of storage, when you "delete" something on SSD, it often is just marked free and will not get actually erased until all of the data next to it is marked as free or the drive runs low on space and triggers a clean up on it's own.

Letting the SSD manage it's fragmentation works better than trying to have the OS micromanage storage that doesn't match traditional hard drive storage mechanics.