The nanostructured dysprosium oxide ( Dy2O3) was synthesized by the co-precipitation method and incorporated with graphitic carbon nitride (g-C3N4) using the ultrasonication method. The resultant product is denoted as Dy2O3/ g-C3N4 nanocomposite which was further used for electrochemical sensing of riboflavin (RF). The physicochemical properties of Dy2O3/ g-C3N4 nanocomposite were examined using several characterization techniques. The obtained results exhibit the nanocomposite formation with the preferred elemental compositions, functional groups, crystalline phase and desired surface morphology. The electrocatalytic performance of Dy2O3/ g-C3N4 nanocomposite was scrutinized with a glassy carbon electrode (GCE) via differential pulse voltammetry (DPV) and cyclic voltammetry (CV) techniques with the conventional three-electrode system. The modified electrode distributes more active surface area suggesting high electrocatalytic activity for the RF detection with two linear ranges (0.001–40 μM and 40–150 μM), a low detection limit of 48 nM and sound sensitivity (2.5261 μA μM−1 cm− 2). Further, the designed sensor possesses high selectivity, excellent stability, repeatability and reproducibility. Finally, the fabricated sensor was successfully estimated for the detection of RF in actual food sample analysis using honey and milk with better recovery.