Canon refers the characteristics of a particular book, movie, TV show, etc. that make up a fandom, as opposed to fanon. Canon can also mean the works themselves. For example, the Harry Potter canon, which is one of the simpler examples, is the seven novels and two shorter books by JK Rowling. Harry, Ron, Hermione, Snape, and the other characters in the books are called canon characters or sometimes just "canons."
The issue of what is and isn't canon is sometimes quite complicated. For example, different books can contradict themselves, usually by accident. There are also works that are questionably canon, like interviews with authors. Movies that are based on books can also be a problem, because a lot of movieverse fanfiction may be written, and people have to decide if the movies make up their own canon.Things that are canon can even stop being canon.
When things get really confusing, fans often postulate that there are several alternate continuities. For instance, the Marvel Universe (referred to as universe 616) is generally accepted to be one canon - if Wolverine states in an issue of X-Men that he likes mint chocolate-chip ice cream, it will be taken as read that when he is missing in the next issue because he's gone to a Dairy Queen with the Runaways, he'll be buying mint chocolate-chip ice cream. However, Ultimate Marvel is considered a different continuity to universe 616, so in Ultimate Marvel, Wolverine's favourite flavour of ice cream may be macadamia. This sort of justification is useful when a franchise has many different shows made by different people (Transformers).
It is generally agreed that fanfiction and most opinions of fans are not canon, although sometimes canon is influenced (for instance, the idea that years are dated before or after the Battle of Yavin in Star Wars is now the official year system in the universe itself).