The three basic morphological forms of cyanobacteria are unicellular, filamentous forms without heterocysts, and filamentous forms with heterocysts. A heterocyst is a large transparent thick-walled cell that is found in the filaments of some cyanobacteria and is the site of nitrogen fixation. Filaments are composed of only two cell types and these are arranged in a one-dimensional pattern similar to beads on a string. The beads on the string are either photosynthetic cells (chloroplasts) or nitrogen fixing cells (heterocysts), these two types of cells work together in one organism to produce their own energy, oxygen and fixed nitrogen. (see image below)

The amount of heterocysts depends on the amount of nitrogen, such as nitrate or ammonium, that is present and available to the cyanobacteria. The heterocyst performs nitrogen fixation in aerobic conditions because the heterocyst cells do not create their own oxygen; that is a job for the adjacent photosynthetic cells. Heterocysts are differentiated and specialized cells that can fix nitrogen, and these are understood to promote survival during low nitrogen conditions. In the absence of fixed nitrogen in the form of nitrate or ammonium, Anabaena and other similar cyanobacteria, produce more heterocysts. These nitrogen-fixing cells form at semi-regular intervals between stretches of vegetative cells to produce a multicellular pattern of single heterocysts every ten to twenty vegetative cells along filaments. It is this delicate combination of photosynthesizing cells and nitrogen fixing cells that makes cyanobacteria so unique!

For more details on heterocysts check out this article https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2845205/