The aim of the study is to understand whether the risk factors of the unplanned extubation (UE) of nasogastric (NG) tubes vary among different inpatient situations. Inpatients who experienced UE between 2009 and 2022 at a medical center were selected, and electronic medical records were used to collect patient background data and their conditions during UE. A total of 302 patients were included in our analysis. Conscious patients were at greater risk of UE when coughing, scratching their nose, blowing their nose, or sneezing than those who were confused (odds ratio [OR] = 0.07, P < 0.001) and those who were drowsy or comatose (OR = 0.15, P = 0.026). During activity, repositioning, bathing, or changing incontinence pads, the risk of UE was higher in patients whose hands were not restrained at the time of UE than in those whose hands were restrained (OR = 0.05, P = 0.004), higher in those with companions than in those without companions (OR = 7.78, P = 0.002), and higher in those with longer NG tube placement time (OR = 1.05, P = 0.008). Accidental extubation (OR = 2.62, P = 0.007) occurred more frequently during activity, repositioning, bathing, or changing incontinence pads. There is an increased risk of UE in conscious patients during activity, repositioning, bathing, or changing incontinence pads. Patients inserted with an NG tube for a longer period of time were at greater risk of accidental extubation during activity, repositioning, bathing, or changing incontinence pads irrespective of whether a companion could aid them if their hands were or were not restrained.