You can generate an arbitrary linear subspace of dimension $d$ by applying an orthogonal transformation on the subspace spanned by the first $d$ basis vectors. However, orthogonal transformations which happen completely inside the subspace have no effect, nor do orthogonal transformations which happen completely in its complement.
Since you need $k(k-1)/2$ parameters to specify an orthogonal transformation in $k$ dimensions, the number of arguments to specify a $d$-dimensional linear subspace of $\mathbb R^n$ is
$$\frac{n(n-1)}{2} - \frac{d(d-1)}{2} - \frac{(n-d)(n-d-1)}{2}$$
To specify an affine subspace of dimension $d$, you need $n-d$ additional parameters to describe the displacement from the origin (displacements in the subspace don't change it).
Here are some examples:
To specify a $0$-dimensional linear subspace, you need $n(n-1)/2 - 0 - n(n-1)/2 = 0$ parameters. That's obvious, because there's only one 0-dimensional linear subspace.
To specify a $1$-dimensional linear subspace (a straight line through the origin), you need $n(n-1)/2 - 0 -(n-1)(n-2)/2 = n-1$ parameters. This is also clear; to specify a one-dimensional subspace, you need to specify one point on the unit sphere, which is $n-1$-dimensional.
To specify a $2$-dimensional linear subspace (a plane through the origin) in $\mathbb R^3$, you need $3\cdot2/2 - 2\cdot1/2 - 1\cdot0/2 = 2$ parameters.
More generically, from the formula you see that you need the same number of parameters to specify a linear subspace and to specify its complement, which is also obvious because one implies the other.
To specify a $1$-dimensional affine subspace (a general straight line) in $\mathbb R^n$, you need $n(n-1)/2 - 0 - (n-1)(n-2)/2 + (n-1) = 2(n-1)$ parameters. This can also be seen directly from the fact that you can write the points of the line as $\mathbf u + \lambda\mathbf v$, (2 vectors $\implies$ 2n parameters) but the length of $v$ is irrelevant (1 parameter less), and $\mathbf u$ can be changed by an arbitrary multiple of $\mathbf v$ (again, 1 parameter less).
Edit: As Elmar Zander noted, the formula for linear subspaces can be simplified significantly to $d(n-d)$.
Obviously this means that the number of affine subspaces then also simplifies to $(d+1)(n-d)$.