The reliability of the diaphragm thickening fraction in predicting weaning failure in mechanically ventilated patients in the intensive care unit (ICU), as well as the relationship between the patients' diaphragmatic inspiratory excursion and diaphragmatic thickness. Fifty mechanically ventilated patients participated in this hospital-based cross-sectional prospective study in a tertiary care teaching hospital. Patients who had been on a mechanical ventilator for at least 7 days and whose legal guardian was willing to provide consent were also included in the research. People with hemodynamic instability and those whose legal guardians were reluctant to comply were excluded. Using diaphragmatic thickening fraction as a diagnostic criterion, the weaning failure group consisted of 24 patients, out of which we predicted diaphragmatic dysfunction (DD) in 19 patients. The weaning success group consisted of 26 patients, of which we predicted no DD in 21 patients. Weaning success or failure was predicted by diaphragmatic thickening fraction with a sensitivity of 79.16% and a specificity of 80.76%, diaphragm excursion with a sensitivity of 70.8% and an 80.7%, and diaphragmatic thickness with a sensitivity of 66.66% and a specificity of 73.91%, respectively. Diagnosing DD in mechanically ventilated, figuring out if extubation would be effective or not, monitoring respiratory effort, and assessing atrophy in ICU patients, ultrasonography may be an effective and accurate technique for mechanical ventilation patients, and it provides a convenient, noninvasive, affordable, and secure way to assess DD.