  In the quiet Sun, magnetic fields are usually observed as small-scale
magnetic elements, `salt and pepper', covering the entire solar surface. By
using 3D radiative MHD numerical simulations we demonstrate that these fields
are a result of local dynamo action in the top layers of the convection zone,
where extremely weak `seed' magnetic fields can locally grow above the mean
equipartition field (e.g., from a $10^{-6}$ G `seed' field to more than 1000 G
magnetic structures). We find that the local dynamo action takes place only in
a shallow, about 500 km deep, subsurface layer, from which the generated field
is transported into deeper layers by convection downdrafts. We demonstrate that
the observed dominance of vertical magnetic fields at the photosphere and the
horizontal fields above the photosphere can be explained by multi-scale
magnetic loops produced by the dynamo.
