They measure the baby's femur length (thigh bone), head circumference and abdominal circumference. The device will calculate an estimated weight based on those measurements. It's just an estimate, as the baby's position may affect getting an accurate measurement. The error margin can be as high as 20-30% but it's a good gauge nonetheless.
Via the scan they have a formula to it.
Thru the scan they can tell
From the ultrasound
Ultrasound