Bacterial proteins are synthesized with an N-formylated amino-terminal methionine, and N-formylated peptides elicit innate-immunity responses against bacterial infections. However, the source of these formylated peptides is not clear, as most bacterial proteins are co-translationally deformylated by peptide deformylase. Here we develop a deformylation assay with translating ribosomes as substrates, to show that the binding of the signal recognition particle (SRP) to signal sequences in nascent proteins on the ribosome prevents deformylation, whereas deformylation of nascent proteins without signal sequence is not affected. Deformylation and its inhibition by SRP are not influenced by trigger factor, a chaperone that interacts with nascent chains on the ribosome. We propose that bacterial inner-membrane proteins, in particular those with N-out topology, can retain their N-terminal formyl group during cotranslational membrane insertion and supply formylated peptides during bacterial infections.