|MadSci Network: Cell Biology|
Your question cuts right to the heart of the field of developmental genetics. This is a difficult question to answer comprehensively, but one that I can try to explain in general terms.
I assume that you are talking about individual cells in a complex organism such as humans. Cells are different because they express different, although overlapping, sets of genes. How does any given cell come to express its unique pattern of genes?
The best place to start is in the embryo. The cytoplasm in the egg cell is not uniform, but various molecules including those which regulate expression of specific sets of genes are unevenly distributed. After fertilization by a sperm cell, the zygote cell undergoes a set of cleavages which divides the zygote into many smaller cells. This process can be compared to slicing up a plate of fruit chunk-containing jello. The chunks are unevenly distributed so that after cutting, one slice might have two pineapple chunks and one pear, another slice might have two pears and five peaches, and so one. If these fruit chunks were akin to proteins in the egg cell that regulate gene expression, we would expect the different cells produced by zygote cleavage to express different sets of genes.
Each of these cells then divides, and an embryo begins to form. If that were all there was to it, only a few different kinds of cells would be produced, and the embryo would stop developing. However, something else happens. This is called positional effect. Cells are constantly communicating with each other. If a cell has six neighbors, it is receiving communications (molecules) from all six neighbors. If those neighboring cells are all different from each other, then the cell in the center is receiving a unique combination of inputs that no other cell in the embryo is receiving. These inputs further refine the set of genes that is expressed, and the cell begins to adopt a unique identity compared with its neighbors.
The next stage is called commitment. At some point, each embryonic cell becomes committed to become a particular kind of cell/tissue/organ. Once this happens, there is no turning back. It is also possible for a committed cell to recruit uncommitted cells to become like it. Again, this requires cell-to-cell communication and the generation of molecular signals that alter gene expression.
The committed cells then follow a developmental program that is genetically determined in which the pattern of gene expression is adjusted until the mature tissue is formed. At this point, the set of genes expressed in the cells involved in forming this tissue becomes more or less fixed.
How gene expression becomes fixed is unclear, but there is evidence that it may be related to a phenomenon called DNA methylation.
Try the links in the MadSci Library for more information on Cell Biology.