We write ‘it’s’ with an apostrophe when it’s a contraction of ‘it is’ or ‘it has’. We don’t use an apostrophe when ‘its’ is a possessive pronoun.
Native speakers sometimes get this wrong and of course it’s tricky for English language learners too. I think people muddle them up because they confuse possessive nouns with possessive pronouns. We explain the difference in this video and also show you how not to rob a bank.