The ultimate form of parasitism and evasion of host immunity is for the parasite genome to enter the germ line of the host species. Retroviruses have invaded the host germ line on the grandest scale, and this is evident in the extraordinary abundance of endogenous retroelements in the genome of all vertebrate species that have been studied. Many of these endogenous retroelements have retained viral characteristics; some also the capacity to replicate and, consequently, the potential to trigger host innate and adaptive immune responses. However, although retroelements are mainly recognized for their pathogenic potential, recent evidence suggests that this 'enemy within' may also have beneficial roles in tuning host immune reactivity. In this Review, we discuss how the immune system recognizes and is shaped by endogenous retroelements.