Doping with heteroatoms allows the retention of the general characteristics of carbon dots while allowing their physicochemical and photochemical properties to be effectively modulated. In this work, we report the preparation of ultrastable P and N co-doped carbon dots (PNCDs) that can be used for the highly selective detection of Fe3+ and the tracking of lysosomes in living cells. Fluorescent PNCDs were facilely prepared via a hydrothermal treatment of ethylenediamine and phytic acid, and they exhibited a high quantum yield of 22.0%. The strong coordination interaction between the phosphorus groups of PNCDs and Fe3+ rendered them efficient probes for use in selective Fe3+ detection, with a detection limit of 0.39 μM, and we demonstrated their practicability by accurately detecting the Fe3+ contents in bio-samples. At the same time, PNCDs exhibited high lysosomal location specificity in different cell lines due to surface lipophilic amino groups, and real-time tracking of the lysosome morphology in HeLa cells was achieved. The present work suggests that the fabrication of heteroatom-doped CDs might be an effective strategy to provide promising tools for cytology, such as organelle tracking.