The ending depends on case and gender.
German has three genders (masculine, feminine and neuter) and four cases (nominative, accusative, dative and genitive).
Genders are completely non-existent in English, and cases only exist for pronouns (he/him, I/me, they/them etc.).
Genders are a way of categorising words into one of three grammatical categories. So there is essentially a different set of grammar rules for each gender. It's important to realise that genders are arbitrary and have nothing to do with biological gender, except that the word for 'it' for masculine and feminine nouns is the same as the word for 'he' and 'she' respectively. I don't know if your native language has genders, but if it does this should be much easier conceptually for you. You have to memorise the gender of every word (although there are some patterns you can recognise to guess the genders of a lot of words).
For example, Katze (cat) is feminine, Hund (dog) is masculine and Buch (book) is neuter. There's no reason for this, and no reason why they couldn't be any other arrangement. You just have to accept that that's what they are.
Ich habe eine Katze. Sie ist groß. - I have a cat. It is big.
Ich habe einen Hund. Er ist groß. - I have a dog. It is big.
Ich habe ein Buch. Es ist groß. - I have a book. It is big.
All three nouns in these examples have the same case (accusative), but different genders. You can see that the ending after 'ein' is different, and different pronouns for 'it' are used. 'Sie' and 'er' can also mean 'she' and 'he' respectively when talking about biological gender. That is the only relationship between grammatical genders and biological genders, and that is why the genders are named masculine, feminine and neuter.
Cases describe a noun's relationship to a verb in a sentence. I won't describe them in detail here, but to start of with you need to know about the nominative and accusative cases.