Seems somebody does not yet deserve his username, huhuhu ;P
If you look at the screen, it's flat. And still we can generate the illusion of depth in 3D games. Distant trees appear farther away than closer trees. That's maybe why it's called depth.
A better term would be distance, imo. Think of depth as the distance of the pixel to the camera, or precisely the distance to the plane we use for planar projection.
The depth buffer stores this distance. It is needed so the distant tree is properly overdrawn by the closer tree, no matter which one we draw first.
Assuming we draw the distant tree first, numbers of 100 are stored on its depth pixels in the framebuffer.
Then, when drawing the closer tree, we calculate a distance of 10. While drawing, we compare depth for each pixel. 100 is farther away than 10, so we overdraw the distant tree with the current closer tree, also replacing depth values of 100 with new values of 10.
If we swap draw order, first drawing the closer tree, and now the distant one, we see the pixels of depth 10 are already closer than our current distance of 100, so we draw no color and no depth.
Early software rasterized 3D games had no depth buffer (or Z-buffer was the name back then).
Instead, a standard solution was to sort the triangles by distance, drawing distant triangles first, close triangles later. This way closer triangles properly overdraw distant triangles.
Another solution was drawing closer triangles first, but then skip parts of a scanline which has been already drawn before. This way we draw only what's visible and waste no work on pixels to be overdrawn anyway later.
Such ideas are still popular today, e.g. if using a depth first pass. This means we draw only to the depth buffer, no colors at all.
After that, we know depth in advance, and can skip over any costly pixel shading which is not visible. That's often a win, even if we have to draw the scene twice.
The ordering topic is also relevant to the alpha value, which is mostly used for transparency, telling hoe transparent or opaque a pixel is, and how it should be blended with former transparent stuff, which also has been drawn to the same current pixel.
Transparency blending is order dependent, so for that we still need to sort triangles (or at least objects) by distance to do this correctly. That's why transparency is still an open problem causing us to use a lot of hacks.
Thus, the common solution is to use alpha testing, not alpha blending. (Think of drawing many leafs of a tree, which usually uses alpha textures to make leafs partially opaque.)
Alpha test means we still store transparency in it's own alpha channel, but when drawing, we only decide to draw the pixel or not. So the alpha channel allows us to add holes to our triangle, but no soft boundary to blend it with the background.
That's no proper transparency, but this way we can still use the simple depth test to draw thousands of leaf triangles.
True alpha blending and sorting is mostly used for special effects and selected geometry like glass windows.
I have never used the stencil buffer, but it's basically a user value. You could use it for example to mark all skin materials on screen, so you can add some screenspace faked subsurface scattering effect later.