The crab at the bottom of this photo is male, the crab at top is female. Notice the difference in the shapes of their abdomens? Male crab have a longer, thinner abdomen; female crab have a shorter, rounder abdomen. They mate in the spring and summer. The process takes several days. For a beautiful description of crab sex go here.
It's illegal to catch female crab, so all the crab you see on the market are, or should be, males.
These crab are Dungeness crab. Each species of crab is its own special snowflake.