To prove cardinality for infinite sets, I know that I have to show that there is a bijection. However, I'm having some trouble defining a function for my sets.
For example: Let O be the set of all odd integers. Prove that O has the same cardinality as 2Z, the set of all even integers.
In this case, I know that I have to define a function which is "Define f: O to 2Z s.t f(n) = n - 1."
However, I don't understand where the n - 1 comes from
The idea here is to define a function in such a way as to show that you can 'match up' pairs of elements for either set. There is nothing particularly special about the function you gave in your example, for example the map: $$ g:O\to 2\mathbb{Z}, n \mapsto n -3 $$ Also gives a bijection between the two sets. You just need to make sure that the function is defined such that it really maps odd integers to even ones. Then you check that such a function is surjective and injective, i.e. that it is a bijection. A good way to build intuition about such function is to try modifying the examples that you've seen before (such as the map $f$ you gave in your question) and see whether they still have the same properties.
Alternatively, you could think about such maps in terms of how they map a particular element. In the example of bijections between the odd integers and the even integers, we can write any odd integer $n$ as $2k+1$ where $k$ is some integer. In this form, we can see that there is an even integer hiding inside the odd one, in a sense, suggesting a map: $$ 2k+1 \mapsto 2k $$ But of course this is precisely the map $f$ you gave as an example.
To show that such a map, say $f$ is onto, we need to show that for every element $m$ in the range, there is an element $n$ in the domain such that $f(n)=m$. For example, to show that $f$ is onto, fix an arbitrary element $m$ in the range, $2\mathbb{Z}$. Now we want to construct an element of $O$ that maps to $m$. This is straightforward, since: $$ f(m+1) = (m+1)-1 = m $$ and since $m$ is even, we know that $m+1$ is odd. Thus we have shown that for any even integer $m$, there exists an odd integer $n$ such that $f(n) = m$. By definition, this means that $f$ is onto.