Middleware in Django is a way to process requests and responses globally. When a user sends a request, it first passes through middleware layers before reaching the view function. Each middleware can modify or check the request. After the view processes the request and returns a response, the response passes back through the middleware layers in reverse order. This lets middleware add features like security checks, logging, or modifying responses. The example code shows middleware printing messages before and after the view runs. The execution table traces each step from request arrival, through middleware, to the view, and back through middleware to the user. Variables like request and response change as they move through middleware and the view. Understanding this flow helps beginners see why middleware matters and how it fits in Django's request handling.