The lifespan context manager in FastAPI controls what happens when the app starts and stops. When the app starts, it enters the lifespan context and runs the startup code before serving any requests. This is shown by the print statement 'Starting up'. Then the app serves requests while the code after yield is paused. When the app receives a shutdown signal, it exits the lifespan context and runs the shutdown code, printing 'Shutting down'. This cleanly manages resources and setup/teardown logic. The execution table shows each step and the app state changes from initialized to serving to stopped. The variable tracker follows the app state through these steps. Understanding this flow helps beginners see how FastAPI manages app lifecycle with the lifespan context manager.