A common trait often associated with multicellularity is cellular differentiation, which is a separation of tasks through the division of labor. In principle, the division of labor does not necessarily have to be constrained to a multicellular setting. In this study, we focus on the possible evolutionary paths leading to terminal differentiation in cyanobacteria. We develop mathematical models for two develop- mental strategies. One, of populations of terminally differentiated single cells surviving by the exchange of common goods. Second, of populations exhibiting terminal differentiation in a multicellular setting. After testing the two strategies against the effect of disruptive mutations (i.e. cheater mutants), we assess the effects of selection on the optimization of the ratio of vegetative (carbon fixing) to hetero- cystous (nitrogen fixing) cells, which in turn leads to the maximization of the carrying capacity for the population density. In addition we compare the performance of differentiated populations to undifferentiated ones that temporally separate tasks in accordance to a day/night cycle. We then compare some predictions of our model with phylogenetic relationships derived from analyzing 16S rRNA sequences of different cyanobacterial strains. In line with studies indicating that group or spatial structure are ways to evolve cooperation and protect against the spread of cheaters, our work shows that compart- mentalization afforded by multicellularity is required to maintain the vegetative/heterocyst division in cyanobacteria. We find that multicellularity allows for selection to optimize the carrying capacity. These results and the phylogenetic analysis indicates that terminally differentiated cyanobacteria evolved after undifferentiated species. In addition we show that, in regimes of short daylight periods, terminally differ- entiated species perform worse than undifferentiated species that follow the day/night cycle; indicating that undifferentiated species have an evolutionary advantage in regimes of short daylight periods.