Intermediate representations are used in compilers to represent programs between the source and target languages. Control flow graphs (CFG) are a common intermediate representation that represent a program as a directed graph with basic blocks as nodes and edges showing possible control transfers. CFGs help optimize programs by breaking them into manageable blocks and making structures like loops and branches explicit. Building a CFG involves identifying basic blocks, which are straight line code sequences without internal jumps, and representing the control flow between them.