There is provided a heat exchanger (1) which can alleviate the effects of stress due to thermal elongation of branch pipes with a more compact structure. The heat exchanger (1) includes: a heat exchange unit (2) which exchanges heat between a refrigerant flowing through an inside thereof and an external fluid; a plurality of hairpin tubes (3) which is installed at an end of the heat exchange unit (2) and serves as an outlet or an inlet of the refrigerant flowing through the inside of the heat exchange unit (2); a plurality of connecting pipes (4) which has one ends thereof connected to the plurality of hairpin tubes (3), respectively; and a header pipe (5) to which the other ends of the plurality of connecting pipes (4) are connected. Each of the plurality of connecting pipes (4) includes a detour section which is bent such that a pipe length becomes longer than a linear distance between the hairpin tube (3) and the header pipe (5).