The unstable triplet excited state is a core problem when developing selfprotective room temperature phosphorescence (RTP) in carbon dots (CDs). Here, fluorine and nitrogen codoped carbon dots (FNCDs) with long-lived triplet excited states, emitting pH-stabilized blue fluorescence and pHresponsive green self-protective RTP, are reported for the first time. The self-protective RTP of FNCDs arises from n-π * electron transitions for CN/CN bonds with a small energy gap between singlet and triplet states at room temperature. Moreover, the interdot/intradot hydrogen bonds and steric protection of CF bonds reduce quenching of RTP by oxygen at room temperature. The RTP emission of FNCDs shows outstanding reversibility, while the blue fluorescence emission has good pH stability. Based on these FNCDs, a data encoding/reading strategy for advanced anticounterfeiting is proposed via time-resolved luminescence imaging techniques, as well as steganography of complex patterns.