The chemical reactions and pathways involving peptidoglycans, any of a class of glycoconjugates found only in bacterial cell walls and consisting of strands of glycosaminoglycan cross-linked by oligopeptides to form a huge and rigid network.