In England, the 'ng' sound is generally used at the end of the word, for example 'long'.
But if the word is extended, e.g. 'longer' , the g is pronounced as a hard consonant.
There are exceptions however. The first g in 'bringing' or 'longing' is often not pronounced as a hard g sound. And in some dialects, notably that of the West Midlands area, the hard g is pronounced wherever ng occurs.
English has many dialects and is not a rule-governed language when it comes to spelling and pronunciation. Just try to listen to as many people as possible speaking English.