Like many grammatical rules and issues, capitalization of the word “earth” is a complicated and somewhat muddied issue. The general consensus among grammarians and linguists is that the word should be capitalized when referring to the planet as a specific place in terms of astronomical reference, but can otherwise be lowercase even when referred to as a specific place. Whenever using the word to refer to soil or ground, the word should be written lowercase, but if writing something like “The Earth travels around the sun” it should be capitalized.
The general rule for capitalization of words in English is that a word should be capitalized at the start of a sentence, or if it is a proper noun. Nouns, typically, come in two forms: either common nouns or proper nouns. The typical explanation for what constitutes a noun is that it is a person, place, thing, or idea. In writing, common nouns should be written lower case, unless at the beginning of a sentence, and proper nouns should be capitalized.
Words such as “pencil,” “dog,” “school,” “nation,” “planet,” “religion,” and “teacher” are all common nouns. They describe a person, place, thing, or idea but are not precise or referring to a specific person, place, thing, or idea. In contrast, names like “Fido” or “Jonathan,” places such as “Iran” or “North Dakota,” things like “Empire State Building,” and ideas like “Supreme Court” or “Christianity” are proper nouns. They refer to a specific thing and are capitalized to reflect that fact.
The problem with the word “earth” is that it, along with a number of other words, can be used as both a common noun and a proper noun. When used to refer to soil, ground, or land, it's almost certainly a common noun, and should not be capitalized unless it is at the beginning of a sentence. “Earth” to indicate a place, however, is somewhat more complicated. In general, if it's being used to refer to the planet, but is not being used in an astronomical context, it should be written lowercase.
For example, if someone writes, “I wish for peace on earth, and good will toward men,” it should be written in lowercase. When “earth” is used to refer to a place in an astronomical context, however, then it is capitalized. So the same person could write, “I wish for peace on Earth, and war against Mars” and it would be accurately capitalized. The definite article “the” is often used before the word to indicate references to the specific planet as well, rather than to the ground or soil. This is often done to indicate that the planet is unique, though it is seldom mandatory and often depends on the flow of the words in the sentence.