Here is some demo code which shows how it works:
// create a temporary texture
D3D11_TEXTURE2D_DESC desc;
depthStencilTexture->GetDesc(&desc);
desc.Usage = D3D11_USAGE_STAGING;
desc.BindFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.MiscFlags = 0;
ID3D11Texture2D* tmpTexture = nullptr;
HRESULT hr = getDevice()->CreateTexture2D(&desc, nullptr, &tmpTexture);
// Copy depth buffer
getImmediateContextD3D()->CopyResource(tmpTexture, depthStencilTexture);
// access depth buffer
D3D11_MAPPED_SUBRESOURCE mappedRes;
getImmediateContextD3D()->Map(tmpTexture, 0, D3D11_MAP_READ, 0, &mappedRes);
unsigned int* color = (unsigned int*)mappedRes.pData;
// Extract 24 depth bits
float depth = static_cast<float>(color & 0x00FFFFFF);
depth /= 16777216f; // divide bei 2^24
// compute a grayscale value [0;255]
unsigned char colorValue = static_cast<unsigned char>(depth * 255.0f);