Many of the ligands for Toll-like receptors (TLRs) are unique to microorganisms, such that receptor activation unequivocally indicates the presence of something foreign. However, a subset of TLRs recognizes nucleic acids, which are present in both the host and foreign microorganisms. This specificity enables broad recognition by virtue of the ubiquity of nucleic acids but also introduces the possibility of self-recognition and autoinflammatory or autoimmune disease. Defining the regulatory mechanisms required to ensure proper discrimination between foreign and self-nucleic acids by TLRs is an area of intense research. Progress over the past decade has revealed a complex array of regulatory mechanisms that ensure maintenance of this delicate balance. These regulatory mechanisms can be divided into a conceptual framework with four categories: compartmentalization, ligand availability, receptor expression and signal transduction. In this Review, we discuss our current understanding of each of these layers of regulation.