When the noun earth refers to our planet, it is capitalized only when it’s a proper noun (meaning it acts like a name and is not preceded by the—for example, everything on Earth). The word is not capitalized when it is a common noun (meaning it does not act like a name and is preceded by the—e.g., everything on the earth).
And of course, earth is sometimes used to mean the soft part of land (synonymous with dirt or soil), in which case it does not need to be capitalized. It can also mean the land surface of the world or the realm of mortal existence without becoming a proper noun.
Earth is often unnecessarily capitalized, but most major publications follow the convention we’ve outlined. For example, Earth is correctly capitalized in these sentences because it is essentially a name (and hence is not preceded by the):
[S]cientists in Europe have for the first time recorded what may be one of the loudest animals on Earth for its size. [USA Today]
This means its light has taken an astonishing 12.9 billion years to reach us here on Earth. [BBC News]
An asteroid the size of a tour bus streaked harmlessly past Earth, passing within 12,230km. [The Southland Times]
And in the following examples, earth is correctly uncapitalized because it’s treated as a common noun (with the article the):
Shale gas is extracted from beneath the surface of the earth through a process called hydraulic fracturing, or “fracking.” [CBC]
Greenhouse gas emissions in volume affect the earth’s climate. [Financial Times]
Because of science, we were able to grasp the age of the earth. [Boston Globe]