I can give you an idea how it kinda works for some things.
When metal is liquid, it’s atoms are all wobbly and depending on how fast you cool it, different structures arise. You might have heard that metal is very well structured, but if you cool it fast, its atoms don’t have the time to structure themselves in a certain way. That will change the properties of the material, metals can be softer or harder depending on this process.
Tempering steel is when you get it red hot. This rearranges the molecules in a way where they are more uniform. Suddenly cooling it rapidly freezes the molecules in that position. This makes the steel more pliableand loose but still hard enough to be effective as a tool or weapon. Without tempering there would be weak spots for the steel to shatter. Like a weak link in the molecular chain where a failure could happen.
Tempering glass is basically heating it up and then cooling it rapidly. The resulting molecular structure makes the glass extremely strong, but it also makes is very brittle, so that when it breaks, the entire piece of glass shatters into tiny fragments. This is very desirable in applications like car windows, not only because the strength of the glass makes it more resistant to breakage, but also when it does break, it doesn’t leave large jagged pieces that could easily cut you.
[This video](https://www.youtube.com/watch?v=xe-f4gokRBs) has a pretty good explanation of a type of tempered glass called a Prince Rupert’s Drop, along with an explanation of the physics behind it.
Since others have covered tempering as it pertains to material science, I’ll cover the cooking part.
Many ingredients (eggs in particular, along with anything made with eggs) tend to ‘curdle’ when heated. This is caused by changes in the proteins that make up the material, and it’s what happens when you scramble eggs. Tempering is the act of very slowly mixing a hotter liquid like boiling water into the ingredient so as to gradually raise its temperature. This is done so that the ingredient stays smooth and fluid without hardening or curdling.
Imagine that you have a big bucket, and you dump a crapload of marbles into that bucket. This is sort of the molecular level of what’s going on when you pour a molten metal.
Much like any loose collection of small objects, the marbles sort of just fell wherever. There are spots where the marbles are more densely packed, but there may also be spots where there are gaps between the marbles (IE structural weaknesses in the metal at a molecular level). What you want is for this bucket of marbles to be situated perfectly to do something, so you find a way to settle the marbles into place.
To do this, you just need to introduce them to the right amount of energy. Vibrating the bucket (or heating the metal) causes the marbles (molecules) to settle into their optimal places. Too much vibration and marbles will spill out (metal fractures, etc), while too little means that it won’t settle properly.
Each metal has its own sweet spot for tempering temperatures.
TL;DR: Tempering is used to ensure that a metal object is structurally consistent on a molecular level, thus strengthening it as a whole.
Latest Answers