I have always thought that there is a probe or sensor kind of thing inside the static port so that it "measures" the static pressure and compare to other pressure sources for airspeed, altitude, and VSI reading.
But my other pilot friend recently told me that the way static port works is because of the air actually flows in and out of it.
For example, when you climb, the ambient pressure decreases so the air will flow out of the static port until it reaches equilibrium, which causes the static pressure inside the casing of altimeter to decrease and the altimeter shows an increase in altitude.
Tried to find answers about how static port work online but did not find a satisfying explanation...
If anyone knows more on this topic please share your opinion.