Artists have many tools that enable them to create illusions in a painting. To create depth on a two dimensional surface, you can utilize linear perspective, temperature, contrast of value, intensity of color and detail. These are all ways to make objects or areas recede or come forward.
In the images below, #1 shows a warm and cool rectangle. You should perceive the warmer one as being closer to you.
The easiest way to make the warmer color appear to be further back, is overlapping, as illustrated in #2. The blue rectangle is obviously in front of the red rectangle.
Or, as in #3, you can make the warmer rectangle less intense or grayer. More intense colors are perceived to be closer to you.
And #4, contrast of value. Objects that are more contrasting, light against dark, appear closer.