The Escherichia coli O104 polysaccharide is an important antigen, which contains sialic acid and is often associated with EHEC clones. Sialic acid is a component of many animal tissues, and its presence in bacterial polysaccharides may contribute to bacterial pathogenicity. We sequenced the genes responsible for O104 antigen synthesis and have found genes which from their sequences are identified as an O antigen polymerase gene, an O antigen flippase gene, three CMP-sialic acid synthesis genes, and three potential glycosyl transferase genes. The E. coli K9 group IB capsular antigen has the same structure as the O104 O antigen, and we find using gene by gene PCR that the K9 gene cluster is essentially the same as that for O104. It appears that the distinction between presence as group IB capsule or O antigen for this structure does not involve any difference in genes present in the O antigen gene cluster. By PCR testing against representative strains for the 166 E. coli O antigens and some randomly selected Gram-negative bacteria, we identified three O antigen genes which are highly specific to O104/K9. This work provides the basis for a sensitive test for rapid detection of O104 E. coli. This is important both for decisions on patient care as early treatment may reduce the risk of life-threatening complications and for a faster response in control of food borne outbreaks.