Accurate prediction of formation tops and lithology plays a critical role in optimizing drilling processes, cost reduction, and risk mitigation in hydrocarbon operations. Although several techniques like well logging, core sampling, cuttings analysis, seismic surveys, and mud logging are available for identifying formation tops, they have limitations such as high costs, lower accuracy, manpower-intensive processes, and time or depth lags that impede real-time estimation. Consequently, this study aims to leverage machine learning models based on easily accessible drilling parameters to predict formation tops and lithologies, overcoming the limitations associated with traditional methods. Data from two wells (A and B) in the Middle East, encompassing drilling mechanical parameters such as rate of penetration (ROP), drill string rotation (DSR), pumping rate (Q), standpipe pressure (SPP), weight on bit (WOB), and torque, were collected for real-field analysis. Machine learning models including Gaussian naive Bayes (GNB), logistic regression (LR), and linear discriminant analysis (LDA) were trained and tested on the data set from well A, while the data set from well B was utilized for model validation as unseen data. The formations of wells A and B consist of four lithologies, namely, sandstone, anhydrite, carbonate/shale, and carbonates, necessitating the development of multiclass classification models. The drilling parameters, specifically the WOB and ROP, exhibited a strong influence on lithology identification. Among the models, GNB demonstrated exceptional performance in predicting formation lithology from the drilling parameters, achieving accuracy and nearly perfect precision, recall, and F1 score for the different classes. LDA and LR models accurately predicted sandstone and carbonate lithologies, although some misclassifications occurred in approximately 5% of points for anhydrite and around 20% in carbonate/shale formations. During validation, the models demonstrated accuracies of around 0.96, 0.95, and 0.92 for the GNB, LR, and LDA, respectively. The study highlights the efficacy of the developed machine learning models in accurately predicting the formation lithology and tops in real time. This is achieved by utilizing readily available drilling parameters, making the approach highly accurate and cost effective by leveraging existing real-time drilling data.