- the number of empty points your stones surround and
- the number of your opponent's stones you've captured (both during the game, and dead stones on the board at the end)
1. According to the rule set used, black and white determine which groups are alive and which stones are dead. They also determine which empty intersections are scoring points. (Non-scoring intersections might be for example dame points, or points in a seki).
2. Remove all dead stones left on the board. These are placed with the other captured stones, black with black, white with white.
1. Take the prisoners and fill them into the territories of the same color: Put the black prisoner stones into black areas. Do the same with the white prisoner stones. If there are any remaining prisoner stones, hold them aside for now.
2. The empty areas may now be rearranged into easy to count rectangular shapes. Stones of one color may be moved from one area to another of the same color in order to make one area a few empty points bigger and the other the same amount smaller. This is done to make the areas rectangular and/or multiples of ten or five in size.
3. For each color, add the size of each empty area together. If there were any left over prisoners of the other color, add them in too. This determines each side's score.
4. If there is Komi, add it to White's score.
5. If there was a handicap, add it to Black's score.
The winner is the player with the higher score. The difference between the winner's score and the losers is how much the winner won by.
There is a Japanese counting example with step-by-step diagrams.
In case the players don't agree on status of groups, the status has to be determined before counting.
Strictly speaking: "at the moment counting starts it is already clear WHAT is scored. You have determined the scoring intersections before starting counting. Whether such determination is merely an application of the rules or whether it is an agreement, this depends on the ruleset in use. -- RobertJasiek"
Japanese rules have a new procedure for determining the status of groups after play has stopped. It is vicarious play with no ko threats, more or less. You can take a ko back if you pass and designate that ko as one you can take back. There are also special seki rules. See Nihon Ki-in 1989 rules.
 This method, in most games, actually computes a players score as their surrounded empty area minus the prisoners of their own color. This is not quite the same number as Territory rules define as the score. However, the winner, and the difference between the scores remains the same.