Here is an example of how basic authentication works on a web server.

A client browser sends an unauthenticated request to the web server for a URL. The server responds with HTTP 401 which means that access to the URL resource requires user authentication with an WWW-Authenticate header. If the browser has access to the username and password combination or the user enters the information, an Authorization header is sent back to the server which consists of the authorization type (Basic) and the encoded username/password pair.

Here is a Wikipedia article For more information on basic authentication and how it works.