Why do machines fail unexpectedly

I’ve been running a CNC machine for a while now, and I’ve noticed it sometimes stops mid-operation without any warning. The other day, I had an issue at the 45-minute mark of a job, and it turned out to be a sensor failure. What are some common causes of these unexpected failures in machinery, and how can we better monitor or prevent them?

‌⁠‍⁠​‍​‍‌⁠‌​​‍​‍​⁠‍‍​‍​‍‌‍‌⁠‌‍⁠‌‌‍‍‍​⁠‌​​‍​‍​‍⁠​​‍​‍‌‍‍⁠​‍​‍​⁠‍‍​‍​‍‌‍⁠‍‌‍‌‌‌⁠‌⁠‌‌⁠⁠‌⁠‌​‌‍⁠⁠‌⁠​​‌‍‍‌‌‍​⁠​‍​‍​‍⁠​​‍​‍‌‍‍‌‌‍‌​​‍​‍​⁠‍‍​‍​‍‌‍⁠‍‌‍‌‌‌⁠‌⁠​‍​‍​‍⁠​​‍​‍‌‍‌​​‍​‍​⁠‍‍​‍​‍​⁠​‍​⁠​​​⁠​‍​⁠‌‍​⁠​​​⁠‍‌​⁠​‍​⁠‌‍​‍​‍​‍⁠​​‍​‍‌‍‍​​‍​‍​⁠‍‍​‍​‍‌‍​‌‌​​⁠‌‍⁠⁠‌​‌⁠‌⁠​‌‌‌​⁠‌‌‍‌‌​‍‌‌​‌‌‌⁠‌​‌‍⁠⁠‌​⁠​‌​‍‌​⁠‌‌‌‌‍​‌‍​‌​‍​‍‌⁠⁠‌​