The game is over when both sides pass. Players should only pass when no more points can be surrounded. In practice, knowing when there are no more points to be surrounded and passing at the correct time is difficult. It may cost points by continuing to play, or you might lose the opportunity to make points by passing too early.
Once both players have passed, the number of surrounded points is counted. Each vacant intersection within a color's territory counts for a point, and so does each captured stone. The player with more points is the winner.