There are two main uses for the apostrophe: to show where a letter is missing and to show that something belongs to something or someone, otherwise known as possession.
The first use -- to show that a letter or letters are missing -- occurs in contractions. Remember contractions? That's when two words are squished together to make one, dislodging a letter or letters in the process.
The last sentence has an example of a contraction -- "that's." The two words that have been squished together are "that" and "is." When you make a contraction of those two words, you drop the "i" and put an apostrophe in its place to show that a letter is missing.
Other examples of contractions are "it's," which means "it is"; "they're," which means "they are"; "you're," which means "you are"; and "who's," which means "who is." I've used these examples in particular because they are ones that are often misused. The reason is they resemble and sound identical to other words, that is, "its," "their," "your," and "whose."
These words I just mentioned are possessive pronouns, which is the confusing part because in general, the other use for apostrophes is when you are using possessive nouns, such as, Jimmy's donut or Audrey's purse. The thing is, when you use a possessive pronoun, rather than a possessive noun, you don't use an apostrophe. Possessive pronouns include his, her, their, your, and its. Confusing, huh?
The thing to remember is that when you use a possessive pronoun, you don't need the apostrophe. You wouldn't say hi's when you mean his, would you? Then you shouldn't use "it's" when you mean "its" either.
An even easier way to remember which word is right is to read your sentence over, adding the letters that have been left out. So when you read "it's" in your writing, think in your head "it is." If it makes sense, you've used the right form. If it doesn't make sense, then maybe you mean "belonging to it," and you should leave the apostrophe out.
Contractions are used in more casual, chatty speech. Formal writing usually uses the more formal forms with no contractions. If you want to be one hundred percent sure of yourself, you can avoid contractions altogether if they are giving you trouble.
However, most online readers appreciate the friendlier feel of contraction use. It makes them feel they are talking to a real person, as most of us use contractions automatically when we speak. The simple practice is to read over what you've written, adding the extra letters in your head and checking for meaning.