Abstract We investigate nitrogen-isotope fractionation in forming and evolving molecular clouds using gas-ice astrochemical simulations. We find that the bulk gas can become depleted in heavy nitrogen (15N) due to the formation of 15N-enriched ices. Around the chemical transition from atomic nitrogen to N2, N15N is selectively photodissociated, which results in the enrichment of 15N in atomic nitrogen. As 15N-enriched atomic nitrogen is converted to ammonia ice via grain surface reactions, the bulk gas is depleted in 15N. The level of 15N depletion in the bulk gas can be up to a factor of two compared to the elemental nitrogen-isotope ratio, depending on the photodesorption yield of ammonia ice. Once the nitrogen isotopes are differentially partitioned between gas and solids in a molecular cloud, the condition should remain in the later stages of star formation (e.g., prestellar core) as long as the sublimation of ammonia ice is inefficient. Our model suggests that all of the N-bearing molecules in the cold gas of star-forming regions can be depleted in 15N, which is at least qualitatively consistent with the observations toward prestellar core L1544. In our models, icy species show both 15N and deuterium fractionation. The fractionation pattern within ice mantles is different between 15N and deuterium, reflecting their fractionation mechanisms; while the concentration of deuterium almost monotonically increases from the lower layers of the ice mantles to the upper layers, the concentration of 15N reaches the maximum at a certain depth and declines toward the surface.