Though we can often determine a butterfly's sex by looking at the most obvious differences in its appearance - like the scent spots of the male monarch or wing pattern/color of tiger swallowtails - the best way to distinguish between males and females, particularly if you aren't intimately acquainted with each species, is actually by looking at the butterfly's genitalia. The genitalia are located at the base of a butterfly's abdomen.
In general, males have claspers which they open and use to grasp the female's abdomen during mating. With the female's abdomen clasped, the butterflies will remain attached until mating is complete. Very occasionally, you might even see this in the wild. I once caught a mating pair of monarchs as the male flew by with a female attached! Hopefully soon, I will have another post on butterfly mating with videos.
Females are a bit trickier as you are looking for the absence of claspers. However in some species, like the monarch, you will note a small divot in the last segment of her abdomen. This is where the male actually grabs on during mating. In addition, most female butterflies have rounder abdomens than males, especially obvious when they are carrying many eggs.
In some species, you might not be able to easily identify the claspers; in fact, I still have trouble with the Heliconius genus. These butterflies are on the smaller side which also makes a clear picture from my phone camera challenging and are mostly found in Central and South America, though a few species range into Mexico and the southern U.S.