A highly photoluminescent small-size carbon dots (CDs) deriving ampicillin sodium were successfully obtained via one-step hydrothermal method. The prepared CDs showed uniform particle size and possessed good excitation-dependent characteristic. The dead bacteria and yeast cells could be selectively stained by the CDs, but the live ones not. It indicated that the CDs possessed a good potential for the live/dead bacteria and yeast differentiation. Cell and plant leaf imaging showed that the prepared CDs possessed low biotoxicity, excellent biocompatibility and multicolor fluorescence emission properties making it a good candidate for bioimaging application. The probe exhibited high selectivity and sensitivity to detect Hg(II) and 2,4-dinitrophenol (2,4-DNP), and excellent linear range of 0–50 μM for Hg(II) (R2 = 0.9920) and 0–25 μM for 2,4-DNP (R2 = 0.9919), with low detection limits of 33.40 nM and 13.44 nM for Hg(II) and 2,4-DNP, respectively. It revealed that dynamic quenching mechanism dominated in Hg(II) quenching the CDs fluorescent, while the quenching mechanism of 2,4-DNP detection belonged to the inner filter effect. The sensor was successfully applied to determine the Hg(II) and 2,4-DNP in real water samples. It shows that the fluorescent nanoprobe shows great promising potential for the detection of environmental pollutants.