Nails falling off for no clear reason is called onychomadesis. It is not a very common condition, and it is very distressing when it occurs for obvious reasons. As you are suspecting, by far the most common cause of nails falling off is in fact trauma, especially if the trauma smashes down on the part of the nail under the cuticle fold where new nail tissue is formed, temporarily disrupting nail production. Sometimes infections of the nail bed, for example those caused by fungus, can have the same effect. This is not the usual effect of a fungal infection of the nail, however, which is more likely to cause thickening, color change, and distortion of the nail. You will also need to consider several more serious underlying conditions, as another common cause of nails falling out is a serious shock to the system temporarily stopping growth of the nails. This can occur, for example, following a serious illness
, from a serious nutrition problem, or from cancer. Finally, several drugs can cause the nails to fall out. By far the most common class of drugs that do this are drugs used in cancer treatment, but a few others can do it as well. In short, the most important thing for you to do is to see your primary care doctor
as soon as possible!