How does image masking work?
You may interpret it this way, but this yields a limited interpretation, because for instance the image may have a maximum different from $255$. 
I consider masking as a product operation. For a binary mask, the values are $0$ and $1$. Thus if $p$ denotes one pixel value, you get $0\times p = 0$ outside the mask, and $1\times p = p$ inside. 

This way, you do not depend on the range of the image anymore. The product can be interpret as the binary AND operation, as you can see in Image masks. The relation between min, max and products could be understood in the more global framework of lattices and Boolean algebras, which are useful in mathematical morphology, and help you define other types of useful masks.  

For more continuous operations on "real-valued" images, you can use masks with values in $[0,1]$, whose product with the image allows dimming between white and black mask areas, using intermediate values. For instance in the following, the mask   masks the left part of an image (black mask values), keep the right part, and  affects attenuated values (smooth transition) in the central part.