A compiler translates the entire source code into machine code before execution, while an interpreter translates and executes the code line by line.