The internet speed test starts by identifying the server closest to you, which is displayed in the lower right-hand corner of the testing window.
A "packet" of information is sent from your device to the server and back. The amount of time it takes for that information to make the trip determines your ping. Next, the speed test downloads and uploads a packet of data over that connection. How quickly your internet can transfer that data from the network to your device and from your device back to the network determines your download and upload speed.
This speed is measured to and from the device you are using to run the test, which means the type of connection has a real impact on the result. A wired (Ethernet) connection straight to the modem will give you the most accurate test of your internet service speed, because the wired connection is the most direct pipeline from the network through the modem/router to your computer.