Both and Both of

Both means the one and also the other.

I want both books.
Both of them are good.
We both want to go.
They are both useful.

Before a noun with a determiner (articles, possessives and demonstratives) both and both of are both possible.

I want both the shirts. OR I want both of the shirts.
Both my parents live abroad. OR Both of my parents live abroad.
Both of these shirts are good. OR Both these shirts are good.

In American English both of is more common than both.

Before a personal pronoun we use both of. Note that both of is followed by the object form of the pronoun.

Both of them have been invited. (NOT Both them have been invited. NOT Both of they have been invited.)
Both of us like riding.

Both can be put after pronouns used as objects.

We have invited both of them. OR We have invited them both.

Negative structures

Both is not used in negative structures. Instead of both…not, we usually use neither.

Neither of them came. (NOT Both of them did not come.)

Position of both

When both refers to the subject of a clause, it goes after the auxiliary verbs and before other verbs. If more than one auxiliary verb is present, both goes after the first.

We can both drive. (auxiliary verb + both + other verb)
We are both interested in philosophy. (auxiliary verb + both + other verb)
We both like riding. (both + other verb)
They both liked the flowers. (both + other verb)

Note that these sentences can also be rewritten using both (of) + noun / pronoun as the subject.

Both of us can drive.
Both of us are interested in philosophy.
Both of us like riding.
Both of them liked the flowers.