Tarmogoyf's power is equal to the number of card types among cards in all graveyards and its toughness is equal to that number plus 1.
If an instant or sorcery spell deals damage to Tarmogoyf or lowers its toughness, that spell is put into its owner’s graveyard before state-based actions are performed. If that card is the first of its type to enter a graveyard, it will raise Tarmogoyf’s toughness before the game checks to see if Tarmogoyf dies.
Tarmogoyf counts card types, not cards. If the only card in all graveyards is a single artifact creature, Tarmogoyf will be 2/3. If the only cards in all graveyards are ten artifact creatures, Tarmogoyf will still be 2/3.
The ability that defines Tarmogoyf’s power and toughness works in all zones, not just the battlefield. If Tarmogoyf is in your graveyard, it will count itself.
The card types that can appear on cards in a graveyard are artifact, creature, enchantment, instant, land, planeswalker, sorcery, and tribal. Legendary, basic, and snow are supertypes, not card types.