This consonant makes two different sounds in Spanish and English, think for example about the sound of the g in the words genius /ˈdʒiːniəs/ and gorilla /ɡəˈrɪlə/. For practical purposes, let's call those sounds soft g and strong g respectively.
Soft G
In Spanish, the soft g is only found in the combinations ge and gi. However, the sound of this g is similar to the English h. Therefore, when we read words like genio /ˈhenjo/or lógico /ˈlo.xiko/, our g sounds exactly like the h in the English words hem or hymn.
I'm sorry I can't add sound to this post, so I hope the comparison with English words helps. If not, you can always go to my YouTube channel to watch the video and hear the sounds.
Strong G
The strong g is achieved with the combinations ga, go, gu. For example:
gato /ˈgato/
gorila /ɡoˈɾila/
agua /ˈaɡwa/
However, that's not all because in Spanish, since vowels are so important and are the basis of our language, we must be able to reproduce each consonant sound with our five vowels.
That means that in each of the sounds described above, I'm missing vowels. So let's see what to do to include them all in both the soft and strong g.
The sound of soft g with the rest of vowels
To achieve the sound of the soft g (h sound in English) with the vowels a, o, u, we won't be able to use g anymore because we would create a different sound. So the only viable solution is to use another consonant: j.
With j, we can achieve all the soft sounds of a soft g:
jarra /ˈhara/
ajo /ˈaho/
juego /ˈhweɡo/
This is why our laughter sound is spelled with J: ja, ja, ja and not with h because this consonant in Spanish is silent.
We can also use j with e and i which means ge/ je and gi/ ji sound the same.
The sound of strong g with the rest of vowels
To make the strong g sound with e and i, we will need more help, in this case, a silent u, and we will spell it like this: gue, gui.
guerra /ˈɡera/
guitarra /ɡiˈtara/
So, the complete list of sounds with the strong is: ga, gue, gui, go, gu.
Remember that the u between g-e and g-i is SILENT.
However...
Sometimes, the u that appears between g-e and g-i does sound -I know, how annoying is this?
Take, for example, the word "pinguino" (penguin), in this case, we do pronounce the u and to indicate it, we add a diacritic accent that almost no one knows in Spanish—and when I say almost no one, I'm not talking about foreign language students but native speakers themselves. This accent is called diéresis and consists of two dots above the sonorous u, so the word becomes pingüino.
Other examples of words whose u sounds even though it's in the middle of g-e/i are:
vergüenza (shame) /beɾˈɣwenθa/
bilingüe (bilingual) /biˈliŋɡwe/
agüita (a bit of water) /aˈɡwita/
So, let's look at all the sounds of G and feel free to download and print the image below:
Find exercises here: https://aprenderespanol.org/gramatica/ortografia-G-J.html