A tire can become deflated for many reasons some examples below

Cracks in the rubber or a small leak in the seal between the tire an rim are the most common causes of this an in most cases the tire can be aired up and safely driven to a facility to be inspected

Many times a tire becomes flat because something has punctured it if it's a small hole like pictured here it can be repaired with a tire plug the tire can be inflated and your on your way with a permanent fix

Tires with larger holes need to be patched from the inside and this is not performed on the road if the damaged area is to large as depicted in the picture the tire can not be repaired and must be replaced