Genetic diversity and fine-scale population structure in the lichen-forming ascomycete Xanthoria parietina was investigated using sequence variation in part of the intergenic spacer (IGS) and the complete internal transcribed spacer (ITS) regions of the nuclear ribosomal DNA. Sampling included 213 and 225 individuals, respectively, from seven populations in two different habitats, bark and rock, on the island Storfosna off the central west coast of Norway. Both markers revealed significant variation and a total of 10 IGS and 16 ITS haplotypes were found. There were no signs of significant positive spatial autocorrelation at any spatial size class down to 10% of transect length, nor did we find significant deviations from neutrality or signs of historical population expansion. Analysis of molecular variance (amova) indicated that most of the genetic variance observed was within populations, but when populations were grouped according to habitat, more than a quarter of the variance was explained among groups. Pairwise comparisons of populations (FST, exact tests of population differentiation) revealed significant differentiation between populations in different habitats (on bark or rock), but not between populations in the same habitat. Haplotype networks show that internal and presumably old haplotypes are shared between habitats, whereas terminal haplotypes tend to be unique to a habitat, mostly bark. We interpret the observed pattern to mean that there is no evidence of restricted gene flow between populations in the same habitat at the present spatial scale (interpopulation distances one or a few kilometres). On the other hand, differentiation between habitats is considerable, which we attribute to restricted gene flow between habitats (habitat isolation). Evidence suggests that the observed differentiation did not evolve locally. Estimates of divergence time between populations in the respective habitats indicate that an ancestral population started to diverge at least 34 000 years ago but probably much further back in time.