The value in the Z-buffer is in range [0.0,1.0]
and 1.0
is the farther distance that is actually contained in the frustum (anything beyond is not visible).
This means that when drawing a pixel of a shape, if its Z-value is lower than the current one, it is nearer to the eye than what's was there (nothing or just another pixel), so Z is updated and pixel is drawn. Otherwise pixel is discarded.