A shadow map is calculated for a light and is used to check what other positions in the world are in shadow from that light. It's a made in two steps.
The shadow map is a depth map from the view of the light source. In it all the objects that will cast shadows need to be rendered. For a directional light it can be a orthographic projection, for others a perspective one. On depth information so simple shaders that only write depth can be used. The shadow map need to be update each time the light or any of the shadow casting objects move.
When rendering a position in the scene transform that position into the space of the shadow map.
Used that light space position to check in the shadow map if the current position is in shadow from the shadow map.
If the position in the scene is in shadow ignore the light else include it's values when calculating the light value.