Lexical analysis is the process of converting a sequence of characters into a sequence of tokens, which are the meaningful units of code used by a compiler or interpreter. It serves as the first phase of a compiler, facilitating syntax analysis by organizing the input into a structured format.