I'm fairly new at Clash of Clans. I noticed sometimes when I attack a village all of a sudden fairies or barbarians come out and attack my troops. How do I know when this is going to happen and how do I protect my troops? Also how do I use that myself and defend my village with them? I assume it has something to do with requesting reinforcements from a clan.
Yes, you are assuming right. Here is how it works:
Clan troops can be requested once you join a clan. Those troops will then move from the donor's camps to the requestor's clan castle. The maximum number of troops that can be received by the requestor is limited to the requestor's clan castle capacity.
Those troops can be used in attacks, or if kept in the castle, will defend the requestor's base whenever enemy troops enter the clan castle's range.
Once a clan castle troop is out, it will usually go to attack the earliest troop that was put down by the attacker until it is down and only then go to the next troop(s).
To get rid of them, the two most common strategies usually start with placing 1 barbarian within reach of a clan castle and out of reach of defenses to test if there are troops inside (no, you can never know for sure whether a clan castle has troops or not unless you scout first, which is possible in revenge raids or clan wars) and place more barbarians one at a time until all castle troops are out.
What follows is then:
Place more barbarians one at a time at the edge of the base to drag out the castle troops and bunch them up, then surround them with barbarians and archers.
Bunch them up by placing barbarians one at a time and zap them out with a lightning spell (those can be unlocked at town hall 5 after building a spell factory).
Usually though, the best defensive units are those that hit both ground and aerial units. This is because you might be faced with balloons for example, that Barbarians and Giants cannot hurt at all.
So the best units are the likes of Archers, Wizards and Dragons which are elixir troops and for later Dark Elixir troops, Minions, Witches, Lava Hounds.
After the type of attack, the type of damage helps too, and splash damage is usually better. One particularity of Witches is that they additionally generate more troops (Skeletons, that however hit only ground troops) that can greatly stall an attacker.
The clan castle can hold 10 troops at level 1, 15 at level 2, 20 at level 3, 25 at level 4, and so on. At level two, a person can get a healer or "fairy.” Usually, if you want to know if they have clan troops, there is no way to tell in a normal battle, but you can guess by looking at the base. If their base has a bunch of debris and tombstones and their gold mines and elixir collectors are full, they probably don't have troops in their clan castle since they’re inactive. Also, if they aren't in a clan, then they probably don't have clan troops.