When rocks and carbon are formed, there are trace (i.e. very small) amounts of radioactive isotopes in them (as impurities).
Radioactive isotopes decay overtime to its decay products (i.e. other elements). Specific radioactive isotopes will have specific decay products. The speed of radioactive decay (called half-life, which is the time it takes for an amount of a radioactive isotope to halve its size) varies for different radioactive isotopes, but scientists have already cataloged all of them.
Now suppose a scientist obtains a rock or carbon sample. She studies the ratio of the radioactive isotope to its decay products within the sample. She then (more or less) plugs the relevant numbers into a mathematical equation (called exponential decay) to approximate the time at which the sample was formed (i.e. the time at which no decay products are present).
For the radiometric dating of the Earth, it's exactly the same thing. Except what's difficult is to find a rock sample that is as old as the Earth to date. But they've found rocks that are very old, and dated to nearly 4 billion years in age. Meteorites instead are more helpful, since they aren't subjected to natural processes on Earth (which destroy samples) to the extent of everything around you. They're indicative of the age of the Earth, because they're formed at about the same time as the Earth.