The distance from the observer and between objects is calculated in our mind by taking several things into account.
The most obvious thing we notice is the relative size of objects, as well how high they appear to be in relation to each other.
In the real world, we do not usually notice that all of the objects but the one we are looking at are out of focus, because as we look at each object we bring it into focus. But we feel something oddly wrong if we view a picture in which everything is in focus, no matter what distance it is from the observer. Also, we have all used focusing devices such as cameras or binoculars in which it becomes obvious that we can only bring something at a specified distance into sharp focus. Everything else blurs out. It is important, then, to use blurring in establishing distance between objects. This is also useful to bring attention to what you think is important in the composition.
The unique local environment the objects are placed in can also give us a clue. Lighting source, haze, and color distortion can help us determine where objects are in relation to each other.
1. Size and relative height.
2. Focal point and blurring.
3. Haze, color, and light distortion.
In many cases, it is enough to use just one of these techniques to show us perspective, but for the best result you should combine all three.
Here is an example of an image in which it is clear that these objects are all the same size and the same distance:

Here, we see that these matrioshka dolls are all a different size, but we perceive them correctly to be the same distance. Why? Because they have the appearance of being on the same level. It is important to make objects more distant from the observer appear higher on the plane than objects closer to the observer. The exception is if the bottom of those objects are on the exact same plane as the line of sight of the observer, but this isn't a recommended view unless you want to confuse your audience.

Are these the same size and distance? It appears so to us.
But look at the same composition from above. We see that they were all different sizes and distances from the observation point of the first view. Adding haze or blur to the composition would have given us more clues.
Sometimes, adding more objects to the picture will give us a better idea as to what the relative distance is. Notice the following two compositions. The only difference between the two are the added walls behind the cone and sphere in the bottom picture. But those make the original horizontal walls appear much farther apart from each other than in the top picture.
So you see, there are many ways to establish distance, using relative size, position, blur, haze, light distortion, and reference objects.
In our next chapter we will look at basic composition rules.