The brominated and/or chlorinated organic compounds (referred to as organohalogens) are frequently detected in natural and engineered environments. However, the ultrahigh resolution mass spectrometry (UHR-MS)-based non-target identification of the organohalogens remains challenging due to the presence of vast number of halogenated and non-halogenated organic molecules in the same aqueous sample. In this study, a new algorithm, namely NOMDBP Code, was developed, based on natural organic matter (NOM) chemistry, to simultaneously identify organohalogens and non-organohalogens from the UHR-MS spectra of natural and engineered waters. In addition to isotopic pattern extraction, for the first time, three optional filter rules (namely selection of minimum non oxygen heteroatoms, inspection of newly formed halogenated disinfection byproducts [X23 DBPs] and precursors) were incorporated in our code, which can accurately identify DBPs associated peaks and further elucidate the X-DBPs generation and transformation mechanisms. The formulae assignment rate against previously reported 2,815 unique organohalogens and their 11,583 isotopologues was determined to be >97%. Application of our algorithm to disinfected NOM indicated that oxygen-containing X-DBPs species accounted for a majority of X-DBPs. Further, brominated X-DBPs (Br-DBPs) during disinfection process were characterized by higher degree of unsaturation compared to chlorinated X-DBPs (Cl-DBPs). Our algorithm also suggested that, in addition to electrophilic substitution and electrophilic addition reactions, the decomposition/transformation is another important mechanism in Br-DBPs formation. Results of this study highlight the superior potential of this code to efficiently detect yet- unknown organohalogens (including organohalogens with non-oxygen heteroatoms) in a non-target manner and identify their generation mechanism during the disinfection process