The visible differences between male (buck) and female (doe) rats becomes more obvious as they mature.
However, the distance between the anus and the genital is always much greater in males compared to females. See photos below.
Two week old buck

Two week old doe

Once the coat becomes thicker, the differences can be harder to see.
Three week old buck

Three week old doe

Note that rats become sexually mature from about 4 1/2 weeks of age, so it is important to separate the sexes by this time. (Breeders who know their lines, will know how much later they can safely leave kittens together, usually around 5 weeks.)
Eight week old buck - testicles become very obvious, although young rats retain the ability to withdraw them (when scared).

Eight week old doe - by this age the vagina will be visible (see the end of this page).

Females also have nipples (two sets of three up each side of their belly), whereas males do not. Sometimes it’s difficult to see nipples, temporarily dampening the underside of your rat with a face cloth can help.
Positioning of nipples on lactating adult doe

Nipples are much smaller normally, as can be seen on this hairless doe

This also clearly shows the vagina just below the female's urethra, males do not have this hole. It is not easily visible in very young rats, but is the most reliable way of checking the sex of an adult.
Author: Vicki Anderson, edited by Mary Giles