In the group stage there are four teams in every group that all play against the other three and the first two qualify for the next round. So you somehow have to rank the teams by their performance.
This works out fine in Group B for example, the Netherlands won all their three games while Chile won two games, Spain one and Australia lost them all. So it's clear: The Netherlands and Chile should advance while the Netherlands should be first and Chile second.
But now we have Group G, Germany has won two games, one draw and should definitely be the winner of that group. But who is second? It's definitly not Ghana, they only got a draw and two losses. But Portugal and the US both have one win, one draw, one loss. So who advances? We need further tie breaker rules.
Now one confusing thing is that those tiebreakers can be different. The UEFA Champions League (best teams from all European nations play against each other) for example would decide by the head-to-head-performance first, which wouldn't make a difference here but if you have formats like the Champions League with two games between everyone in a group it can make one.
The FIFA World Cup uses the goal difference as the first tiebreaker. If someone won against Team A by four goals and lost against Team B by one goal he seems to be better than someone who narrowly won against Team A by one goal and lost against Team B by four goals, right? I mean you can compare to that to basketball or ice hockey as well, a narrow win usually means a far more balanced game.
So you take the numbers of goals for and against each team. The draw between the US and Portugal doesn't matter because they both scored two goals against each other. Just like they both won 2-1 against Ghana. So the deciding factor is their performance against the fourth team, Germany. Now Portugal lost 0-4 to Germany while the US lost 0-1. So the US has four less goals scored against them during the whole group stage. Which means they both scored and received four goals. Portugal scored four times as well but got seven goals against them. Definitely worse.
tl;dr: Losing by one goal is better than losing by four goals.