The ringing in the ear after listening to loud music happens due to micro trauma to the cilia present in the ear. It is called an acquired tinnitus.
Cilia or Hair cells act as the gatekeepers of our hearing. When sound waves hit them, they convert those vibrations into electrical currents that our auditory nerves carry to the brain. The cilia move according to the amplitude of the sound. This motion triggers an electrochemical current that sends the information from the sound waves through the auditory nerves to the brain. These cells help in relaying the sound back to the brain. Loud music causes destruction of these cilliary cells and the sound is relayed to the brain is relayed in a form of a static. It is this static the brain perceives is tinnitus or ringing sound.
AS these cilia re grow in about an hour; tinnitus is usually a temporary phenomenon. But regular trauma to the cilia decreases its potential to re grow and leads to permanent deafness.
I would recommend the following.
1)Do not listen to loud music for prolonged time. Listening to music on speakers is safer than to listen on the ear phones.
2)Take regular, scheduled breaks from listening to loud music as prolonged loud music has adverse effect on hearing.
3)Use good quality ear phones that keep the decibel level of the music below the amplitude that causes ear damage.
4)Consult a doctor if the ringing sound continues for more than 24 hrs.