Alphabeta T cells pass through a series of lymphoid tissue stromal microenvironments to acquire self tolerance and functional competence. In the thymus, positive selection of the developing T-cell receptor repertoire occurs in the cortex, whereas events in the medulla purge the system of self reactivity. T cells that survive are exported to secondary lymphoid organs where they direct first primary and then memory immune responses. This Review focuses on the microenvironments that nurture T-cell development rather than on T cells themselves. We summarize current knowledge on the formation of thymic epithelial-cell microenvironments, and highlight similarities between the environments that produce T cells and those that select and maintain them during immune responses.