Relationships between different animals are established through taxonomy. Taxonomy is the classification of living things. These classifications are broken down as follows from the largest grouping to an individual species of animal: Kingdom, phylum, subphylum, class, order, family, genus, species. Animals that are in the same species are very closely related, and animals in the same kingdom are very distantly related. For instance, all animals are part of one kingdom, Animalia, and all plants are in the kingdom Plantea.
All spiders and crabs are in the phylum Arthopodia, as are all insects. Arthropods are distinguished physically by the fact that they all have segmented, jointed legs and have an exoskeleton. While both crabs and spiders are grouped in the same phylum, this does not mean that they are necessarily closely related. For instance, all animals with a spine are in the phylum Cordata. But it is clear that although fish and monkeys both have spines, they are very different.
Subphylum Cheilcerata and Subphylum Mandibulata
The division between spiders and most crabs happens at the subphylum level. Spiders are in the subphylum Cheilcerata, while most crabs are in the subphylum Mandibulata. The difference is largely that crabs have a mandible, a type of jaw, and spiders have chelicerae, which are mouth parts that appear before the mouth. The "fangs" of spiders are the chelicerae.
Horseshoe crabs are in the same subphylum as spiders, Cheilcerata. This makes horseshoe crabs more closely related to spiders than they are even to other crabs. Like spiders, horseshoe crabs do not have a mandible and instead have chelicerae in front of their mouth parts. Spiders and horseshoe crabs are divided at the level of class. Spiders are in the class Arachnida, while horseshoe crabs are in the class Merostomata.
Another crablike creature used to exist and is classified also in the subphylum Cheilcerata. These are called "sea scorpions." They went extinct about 250 million years ago. These "scorpions" had a larger stinger on the back of their tail and grew to larger than 6 feet in length. This makes them possibly the largest arthropod that ever lived. Their inclusion in the subphylum Cheilcerata makes these ancient crablike scorpions also more closely related to spiders than to crabs.