Water barely compresses, and it grows when it warms. Fill a heating loop at 50 °F and run it to a 180 °F average, and the water wants about 3% more room than the pipes gave it. In a closed loop with nowhere for that water to go, the pressure climbs by tens of psi for every degree. The relief valve on the boiler would lift within a few degrees of warming, dump water on the floor, and then the loop would come back short of water when it cooled. The expansion tank is the room. It holds a cushion of air that the extra water squeezes as the system warms and gives back as it cools, so the pressure moves a few psi instead of a few hundred.
The tank has a second job that gets less attention: it is the one place in the system whose pressure the pump cannot change. A pump only adds a pressure difference, so wherever the tank connects is the reference the rest of the loop floats around. That point of no pressure change is why the tank belongs at the pump suction. Put it at the discharge instead and the pump pulls the far side of the loop down, which is how air gets drawn in at the high points and how pumps start to cavitate.
Sizing is a squeeze between two pressures. When the system is cold, the highest point in the building still needs a few psi so the air vents push air out instead of pulling it in. That sets P₁. When the system is at its hottest, the relief valve has to stay closed with some margin. That sets P₂. The tank's air has to hold the whole expansion between those two pressures, and the tank size comes from Boyle's law: the closer P₁ is to P₂, the less air each gallon of tank is worth, and the bigger the tank gets.
Where the tank sits in the building decides what P₁ and P₂ are at the tank. Put it in the basement mechanical room next to the boiler and it carries the full static head of the building on top of the minimum at the roof, so P₁ is high and the two pressures sit close together. Move the same tank to the top and P₁ drops to almost nothing, while P₂ only drops by the same amount of head. In absolute terms the ratio between them opens up, and the tank shrinks, often by a third or more. The pressures at the top and bottom of the system do not change at all; the building sets those. A taller building also eats into the relief valve's room: every 2.3 ft of height costs 1 psi before the water has warmed at all, which is why tall buildings move to higher-rated equipment or split into pressure zones.
Two more things to watch in the figure. A plain steel tank, where the water touches the air, starts with its air at atmospheric pressure, so much of it fills with water just from filling the system; a precharged diaphragm tank starts with all of its air already at P₁ and is much smaller. And chilled water still needs a tank: the loop is filled cool, but it can sit idle through a summer shutdown and warm toward room temperature, so it is sized for that, not for its 44 °F supply.