For example, if a Pope dies in a given year, then he is soon replaced, and for that year there were 2 Popes. However, sometimes a Pope dies shortly after his appointment, and that year may have 3 Popes. At various times there have also been multiple people claiming to be the pope, so they could cause the number to increase further. What was the year with the most Popes?
It depends on how you count, but 3-4.
The most people claiming at once to be pope probably came in the 15th c. At the very end of the Western Schism, between 1409 and 1415, you had three claimants to the papacy: Benedict XIII (Avignion), Gregory XII (Rome), and Alexander V/John XXIII (Pisa). Martin V was elected in 1417 and the schism ended, but Gregory XII died the month before, so you still had only 3 living people who claimed papal status.
You have several triplicates of reigning popes. For these, I would suspect that in a great number of cases, middle pope was bumped off by his successor, particularly since most (all) occur at times of particular crisis for the papacy:
*Formosus (891-896), Boniface VI (896), and Stephen VI (896-897).
*Benedict IV (d. July 903), Leo V (July-Dec.), Sergius III (Jan. 904 - 911). Note that the medieval year usually began not in January, but at Easter.
*John XII (Feb-May, 964), Benedict V (May-June 964), Leo VIII (June 964 - 965)
*Sylvester II (d. May 1003), John XVII (May-Nov. 1003), John XVIII (Dec. 1003 - 1009)
*Urban III (d. Oct. 1187), Gregory VIII (Oct.-Dec. 1187), Clement III (Dec. 1187 - 1191)
*Alexander VI (d. Aug. 1503), Pius III (Sept.-Oct. 1503), Julius II (Oct. 1503 - 1513)
*Julius III (d. March 1555), Marcellus II (April-May 1555), Paul IV (May 1555 - 1559)
*Sixtus V (d. Aug. 1590), Urban VII (Sept. 1590), Gregory XIV (Dec. 1590 - 1591)
*Gregory XVI (d. Oct. 1591), Innocent IX (Oct.-Dec. 1591), Clement VIII (Jan. 1592 - 1605)
*Clement VIII (d. March 1605), Leo XI (April 1605), Paul V (May 1605 - 1621)
There are two times when you had four reigning popes in the same year:
*Benedict IX (d. Dec. 1044), Sylvester III (Jan.-March 1045), Benedict IX (March-May 1045), Gregory VI (May 1045 - 1046)
*Gregory X (d. Jan 1276), Innocent V (Jan.-June 1276), Adrian V (Jul.-Aug. 1276), John XXI (Sept. 1276 - 1277)