Cyclic dinucleotides (CDNs) have central roles in bacterial homeostasis and virulence by acting as nucleotide second messengers. Bacterial CDNs also elicit immune responses during infection when they are detected by pattern-recognition receptors in animal cells. Here we perform a systematic biochemical screen for bacterial signalling nucleotides and discover a large family of cGAS/DncV-like nucleotidyltransferases (CD-NTases) that use both purine and pyrimidine nucleotides to synthesize a diverse range of CDNs. A series of crystal structures establish CD-NTases as a structurally conserved family and reveal key contacts in the enzyme active-site lid that direct purine or pyrimidine selection. CD-NTase products are not restricted to CDNs and also include an unexpected class of cyclic trinucleotide compounds. Biochemical and cellular analyses of CD-NTase signalling nucleotides demonstrate that these cyclic di- and trinucleotides activate distinct host receptors and thus may modulate the interaction of both pathogens and commensal microbiota with their animal and plant hosts.