Hello,
It is due to formation of subungual hematoma. A subungual hematoma is caused by collection of blood (hematoma) underneath a toenail or fingernail. Keep the hand elevated and apply cold compresses by wrapping ice cubes in a towel. Please ensure not to apply ice directly without any cloth. Also take some anti inflammatory medicine like Ibuprofen or Diclofenac if you have taken them prior to this injury and have not shown any allergic reaction to them.
Also consult a doctor because any hematoma which is covering more than 25 % of the area has to be evaluated by a doctor. If there is any nail removal then soak it with an antiseptic and apply some antibiotic cream like Neosporin or Bactroban. Surgical technique for draining the hematoma like cautery, needle drilling or removing the entire nail to release the blood may be required.
It is very difficult to precisely confirm a diagnosis without examination and investigations and the answer is based on the medical information provided. For exact diagnosis, you are requested to consult your doctor. I sincerely hope that helps. Take care and please do keep me posted on how you are doing.
have you had your sugar tested? sometimes the first things that show when you have an undiagnosed form of diabetes is your feet.