oh and how do they get microsd cards that small? it's incredible and i've never understood it fully. are there fundamentally different chips in a 2gb and a 128gb card or is it just scaled versions of the same thing?

they are exactly the same thing. they are not even scaled down.

in fact, what you find in an SSD, when you look at the mechanism used to achieve nonvolatile storage without any mechanical parts, is also exactly the same. same thing with USB drives, same thing with your phone’s storage.

when we discovered how to “print” electrical circuits on silicon wafers and recreate the functionality of the thumbtack-sized basic electrical components residing on now-obsolete circuit boards, we initially only used them for transformative, volatile hardware components like basic microcontrollers and the like. things that did stuff with data provided to them instead of simply storing data in any capacity. it was very expensive to design and manufacture these sorts of silicon circuits and logically you’d spend your money on the most functional part of the machine in order to get the best performance/cost ratio

these are called integrated circuits and we got really good at making them. today we can print a certain kind of incredibly important electrical component, called a transistor, onto them just 14 nanometers apart. it follows that on an silicon wafer the size of, say, half a playing card you can print literally a few billion cpu-grade transistors.

“cpu grade” transistors are kind of special in that they should never malfunction  or wear out, regardless of how much they’re used. they also have to be manufactured in a way that guarantees every single one is inscribed correctly, as a handful of defects will render a CPU forever useless. this results in them taking up more wafer space than the transistor im about to talk about

the requirements for storage-grade transistors, which is what is used to hold nonvolatile, binary data in all the devices i named at the top of the post, can be made much, MUCH smaller. you can print tens of billions or even 100s of billions of them on a chip much smaller than half a playing card. this is because not every single one of them has to work, and certainly a number of them won’t. that’s why if you inspect the actual size reported by a USB drive, or sd card, or even hard drive, you’ll find a seemingly random, ugly number that’s just short of what’s reported on the box it came in. 

to talk more about the functional side of these things, you can think of transistors as switches. they are either on or off, and this state of being on or off does not necessarily depend on a voltage being applied so long as you network them correctly.

around five or so transistors (depending on details i dont want to get into) can be linked together to form a flip-flop (yes, that’s actually what they’re called) which itself can be understood as a single entity that can either hold a 1 or a 0 and can also be reset or set to change a 0 to a 1 or vice versa. the configuration of transistors used to create a single flip flop for the purpose of nonvolatile storage involves a NAND gate, which is a logic gate similar to the AND gate. the kind of technology used in SD cards, usbs, SSDs, etc is ALWAYS NAND flash memory

now, you may think you’ve finished the race by being able to group a bunch of flip-flops on an IC, but it gets more complicated. any type of flash storage, much like any type of other non-volatile storage, is composed of blocks. blocks have a nice, round fixed size like 1MB or 512KB. depending on the total capacity of your device, you probably have anywhere between 1000-20,000 blocks which are numbered from block 0 to block 1000 (or whatever). the circuitry comprising the controller on your flash storage device does the job of keeping track of which block maps to which network of NAND storage which is how it’s presented to the computer it’s plugged into. the kernel running on that computer issues commands based of this block paradigm, since it knows what bytes have to go where but doesn’t know or care about the functional implementation of how those bytes are stored.

ANYWAY, i was getting off topic, blocks are comprised of many individual pages which themself are composed of the NAND transistor groups we talked about before. usually a page is about a KB or so, and this is where the magic happens

i said before that some amount of manufacturing errors are going to occur meaning some pages and blocks are going to be crap. they’ll be stuck at 1, stuck at 0, or doing some shit other than holding exactly the value given to it by the controller until the controller decides to change it.

a page has, like we said, about 1KB or so of flip-flops available to it. of those, all but maybe 64 or so will be dedicated towards actually storing binary bits. the 64 that aren’t hold something we call a checksum value, which is the product of an avalanching hashing function whose input is every other flip flop.

this is tough so stick with me

when i say avalanching hashing function, i’m talking about an idea implemented in yet another circuit on board your device that looks at all the flip-flops that aren’t those special 64 we talked about earlier and generates a 64 bit number based off them, which is stored in a place i bet you can guess.

if i change even one of the input values, if i literally just change one ‘0′ to ‘1′ or vice versa, the 64 bit value i get out will be radically different with overwhelming probability.

so if one bit goes bad, we’ll be able to tell because we’ll write value X to that page, then read it back and check whether the value we read back matches what the checksum should be. if it doesn’t, that page is bad, and then the controller circuit on the device makes a special note to NEVER use it, nor even the block, again. the data is then written to a special, reserve block that has never been used before, and has been kept on reserve for situations like this.

this will happen a number of times until you run out of those special reserve blocks, which triggers the controller to mark the storage device as “read only” (as reading does not adversely affect the workings of these components like writing does).

and that’s how we are able to store 64 GB of information on something smaller than your pinky nail with zero chance of data loss or corruption