The best way to sex a hamster is to either hold them on their back, or if you know how to, you can also scruff them. Assuming your hamster is new, though, and not properly socialized, this probably isn’t such a good idea and instead you can put them in a clear container to look under.
Male hamsters, especially Chinese and Syrian hamsters, have large scrotums. Sometimes you won’t see their testicles, because they are tucked up, but when a hamster is warm or comfortable they may come out, sometimes only one does, that is normal.
Another easy way to tell if your hamster is male or female is to look at the distance between their genitals. Males are distanced further apart while females have them very close.
Depending on how furry your hamster is, sometimes you can see the female's nipples, this is especially true for when they are pups.
A common misconception, especially with dwarf hamsters, is that only males have scent glands. This is false, all sexes have them, but you can see them clearer on males. Dwarf hamsters have a single scent gland on their stomach, whereas Syrians and Chinese have two on their flanks.
Female hamsters go into heat around every four days. From my experience, it isn’t very easy to tell with the exception of Syrians. When a Syrian is in heat she will often act a bit “crazier” and will develop a stronger odor. If you stroke her on her back her tail will lift, but please don't do that as it is an involuntary action.

Dwarf Hamster Sexing