A compiler acts as a translator that converts programs written in high-level human-readable languages into machine-readable low-level languages. Compilers are needed because computers can only understand machine languages, not human languages. A compiler performs analysis and synthesis on a program, breaking the process into phases like scanning, parsing, code generation, and optimization to translate the high-level code into an executable form. The phases include lexical analysis, syntax analysis, semantic analysis, code generation, and optimization.