Go to the doctor. I had one earlier this year and it was terrible. It hurt to put shoes on, it was excruciating when I stubbed my toe and it was infected.
I went to the doctor, he numbed it (the needle going into my toe was the worst part of the visit), cut the nail all the way back to the matrix and bandaged me up. My toe was numb for the next day but it was instantly better. He recommended that I come back if it returned and he would cauterize the root of the nail.
I had it clipped in March and it still has not come back.
This can be caused by either trimming the nail improperly or damaging the matrix of the nail.