We investigate the formation of neutral magnesium lines in the solar p
hotosphere with an atomic model containing 83 levels plus the ground s
tate of Mg Ir connected via radiative and collisional interactions. Sy
nthetic line flux and intensity profiles are compared with the solar s
pectrum to study the relevant physical processes and their influence o
n the level populations and line profiles. For neutral magnesium with
the photoionization edges of its three lowest states at lambda lambda
1620, 2514 and 3757 Angstrom the reduction of the ultraviolet radiatio
n field due to metallic line absorption has been taken into account us
ing Kurucz' (1992) ODF opacities. In the photosphere of a cool star ex
citation and ionization due to collisions with neutral hydrogen can ou
tweigh electron collisions. Therefore the influence of different types
of collisional interactions with electrons and neutral hydrogen atoms
is examined. General agreement with solar line profiles in the visibl
e and infrared is found for an atomic model with both electron collisi
ons and strongly reduced but significantly large neutral hydrogen coll
ision rates. Our investigation thus extends previous results to lines
of all different excitation energies. The atomic model found from the
analysis of the solar spectrum will serve as a reference for the inves
tigation of cool metal-poor stars in which both the reduced electron c
ollision rates and the enhanced UV intensities lead us to expect more
pronounced deviations from LTE.