This is sort of a geeky physics/gas law question, but I thought someone here might be able to answer it for me or at least point me in the right direction. I've been diving for over 40 years, but I've never really understood why tanks get hot when you fill them from other tanks. I signed up here just to ask.

I understand why tanks get hot when filled directly from a compressor, or at least I think I do. You start with a lot of air out in the atmosphere - a large volume V1. You compress that air with a compressor and it gets hot as you stuff it into the small tank - a smaller volume V2. I looked up "adiabatic heating" and I understand it. I even went through the equation for an ideal gas (PV=nRT). That equation has two unknowns if I stick in the volume change. I was able to figure out that a second equation comes from the effect of the number of degrees of freedom of nitrogen N2 and oxygen O2 diatomic molecules (PV**gamma is constant). Those two equations allows one to solve for temperature T and pressure P given the change in volume V. Gamma is derived from the number of degrees of freedom of the molecules and is also equal to the ratio of heat capacity at constant pressure to heat capacity for constant volume - roughly 1.4 for air.

Another way of looking at why the tank gets hot (when filled directly from the compressor) is just to notice that you are running a pump and putting energy into the system by compressing the air. At least it makes sense that adding energy makes it hot. You could get that energy out again by running a pneumatic motor from the scuba tank. I'm pretty sure that one could (at least in theory if we imagined perfect compressors, no frictions, no heat gain/loss, etc.) let the hot filled tank expand out into the atmosphere and get back to where you started with all the gas at room temp and atmospheric pressure.

But that's as far as I got. Why does the scuba tank also get hot when filled from a higher pressure tank (or a bank array of higher pressure tanks? This has always bugged me. When the array of tanks was filled by the compressor, they got hot. At that point it's just like the first case of directly filling the scuba tank from the compressor. At least in theory it could expand out and the whole thing would return to the starting temp/pressure/volume.

So when you let the air out of a high pressure tank to fill a scuba tank, you are going from the initial high pressure small volume in the fill tank to lower pressure, larger volume, in the volume making up the fill tank plus the scuba tank. You aren't adding any energy like you did with the compressor in the first case. In fact, since the fill tank was allowed to cool after it was filled, it makes sense that it cools off below room temp. But why in heck does the scuba tank get hot? You're doing the opposite of the first case - you are now going from high pressure small volume to lower pressure larger volume. Shouldn't the air cool off? Why does the scuba tank get hot in both cases when you are doing the opposite thing in those two cases?

I've looked on the web and found some stuff, including some questions just like the one I asked, but I'm pretty sure the answers are wrong.

I know it's not because the remaining air in the scuba tank being filled gets compressed. The tank gets hot even if it was at a a vacuum when filled.

Thanks, in advance, for any help on this.