Now, while the topic of white balance is complex, the fundamental concept is not. Firstoff, white balance really isn’t about the color temperature of the light, that number can only be reliably measured at the scene, so when you take your picture and walk away that number becomes a contrivance. “White Balance” itself is simply about making a thing in the image that’s supposed to be white, actually look white.
So, using the simple 0-255 range of 8-bit JPEGs, what you want is for a pixel from a known-white part of the scene to be where the red, green and blue channels are all 255. So, if you take that pixel from the image and R=200, G=255, and B=180, then you know the channels need to be modified to make R=G=B=255. Typically G is left alone and the R and B channels are multiplied to skew them to G. So, for my arbitrary example the R multiplier would be 255/200=1.275 and the B multiplier would be 255/180=1.417. That’s the essential calculation of white balance.
In the image metadata, the camera will record it’s white balance assertion as multipliers, but it’s not so obvious that’s what they are. My Nikon D7000 delivers a tag that looks like this:
[MakerNotes] WB_GRBGLevels: 256 537 337 256
So, note the G values are on the ends, and the actual multiplier is calculated from these numbers like this, 537/256=2.097 for R, and 337/256=1.316 for B.
I’ve noticed some cameras use 1024 as the green reference.
Like I said, color temperature after you leave the scene is a contrivance. The Kelvin number can be somewhat divined from the multipliers, but the equation is discontinuous and not always close to the scene measurement. This is complicated by what @jdc points out, scenes that are illuminated by different lighting will be impossible to accurately characterize by a single set of multipliers, much less a translation to a color temperature. The mainstream softwares give you such a number because that’s how you think of the light, but really, you’re dealing with the encoded image. Adobe’s DNG processing uses color temperature (dual-illuminant color profiles) to determine a color transform for the camera and the scene it recorded, but you have to have a really good temp number to use it to full effect.
Hope this helps. Welcome to the forum; you’ve come to a good place to learn such; I speak from direct experience.