O-antigen (O-polysaccharide) is a highly variable part of the lipopolysaccharide present in the outer membrane of Gram-negative bacteria, which is used as the basis for bacterial serotyping and is essential for the full function and virulence of bacteria. In this work, the structure and genetics of the O-antigens of Escherichia coli O118 and O151 were investigated. Both O-polysaccharides were found to contain ribitol phosphate and have similar structures, the only difference between their backbones being one linkage mode (β1→3 in E. coli O118 vs. β1→2 in E. coli O151), which, most probably, is the linkage between the oligosaccharide repeats (O-units). The O-antigen gene clusters of the two bacteria are organized in the same manner and share high-level identity (>99%). Analysis of the wzy genes from E. coli O118 and O151 strains, which are responsible for the linkage between O-units, revealed only one nucleotide substitution, resulting in one amino acid residue substitution. The possible genetic events that may lead to the structural difference between two O-antigen structures are discussed. Salmonella O47 has the same O-unit backbone and a similar O-antigen gene cluster (OGC) (the DNA identity ranges from 74% to 83%) as E. coli O118 and O151. It was suggested that the OGCs of the three bacteria studied originated from a common ancestor.