The codimension of $X=Z(f_1,\ldots,f_k)$ in $\mathbf{A}^n$ equals $k$, or equivalently, the dimension of $X$ is $n-k$, if $(f_1,\ldots,f_k)$ is a regular sequence.
Let me explain what a regular sequence is. Sorry if I'm writing things you already know.
Let $A$ be a noetherian ring. An element $x\in A$ is called regular if the multiplication by $x$ is injective. A sequence $(x_1,\ldots,x_n)$ of elements $x_1,\ldots,x_n\in A$ is said to be a regular sequence if $x_1$ is regular and the image of $x_i$ in $A/(x_1A+\ldots+ x_{i-1}A)$ is regular for all $i=2,\ldots,n$.
You can use Krull's principal ideal theorem to show that any ideal $I$ of $A$ which can be generated by a regular sequence $(x_1,\ldots,x_r)$ satisfies $\textrm{ht}( I) = r$.
So one way to find out if the dimension of $X$ is $n-k$ is to check the above condition.
If $k=1$ and $f_1\neq 0$ we're good.
Let's see how it goes for $k=2$. Let's suppose that $f_1\neq 0$ and that $f_2 $ is not contained in the ideal $(f_1)$. Now, you have to check that the image of $f_2$ in $k[x_1,\ldots,x_n]/(f_1)$ is regular. So you compute the quotient and check if it's an integral domain. If it's an integral domain, we're good. If not, it might be a bit more difficult to check if $f_2$ is regular in $k[x_1,\ldots,x_n]/(f_1)$. I wouldn't know a fast way of checking if this element is a non-zero divisor at the moment.
This is not a complete answer but I hope it at least helped a bit.
NB: This answer is directed to the questions about the real case, not the complex case, which was already treated by Francesco. Added 5 July 2021: Because of some questions I have received over the years since this was written, I have realized that there are a few places where the logic and flow are not completely transparent, so I have decided to make a few small changes to clarify those points.
In some sense, the reason you are running into these 'problems' is that you are working with the ring of real polynomials rather than the ring of (germs of) real-valued analytic functions, which is also a UFD. For example, it is not hard to show that there is a (unique) real-valued, real-analytic function $f$ defined in a neighborhood of $0$ and satisfying $f(0)=\frac12$ such that
$$
y^3 + 2x^2y-x^4 = \bigl(y - x^2f(x^2)\bigr)\bigl(y^2 + x^2f(x^2) y + x^2/f(x^2)\bigr),
$$
so $y^3 + 2x^2y-x^4$ is reducible in the ring of real-valued, real analytic functions defined on a neighborhood of the origin. The curve $y = x^2f(x^2)$ is smooth (in fact, real-analytic, of course), but the $y$-discriminant of the quadratic factor is $x^4f(x^2)^2-4x^2/f(x^2) = -8x^2 + \cdots$, so the only real point of $y^2 + x^2f(x^2) y + x^2/f(x^2)=0$ near the origin is the origin itself. (The quadratic factor is irreducible in the ring of real-valued analytic functions defined on a neighborhood of the origin.)
Thus, a more easily approached question is: Suppose that the origin is a singular zero of an irreducible element $f$ in the ring of real-valued analytic functions defined on a neighborhood of the origin (i.e., real-analytic germs). Can the zero locus of $f$ be a nonsingular real-analytic hypersurface near the origin?
The answer to this question is 'no' because near a nonsingular point of such a hypersurface, there will always be a real-analytic function $g$ that vanishes on it whose differential at that point is nonvanishing. However, this will imply that $g$ is a factor of $f$, which is assumed to be irreducible.
There remains the question of whether the zero locus of an irreducible real-analytic germ $f$ that is singular at the origin could contain a smooth hypersurface passing through the origin.
The answer to this is also 'no', but it takes a little work to see this.
The case of a curve is not hard, using some standard facts about resolution of curve singularities: If $f(x,y)$ is a nonzero, real-valued analytic function defined on a neighborhood of the origin in $\mathbb{R}^2$ that is irreducible in the ring of analytic germs at the origin and satisfies $f_x(0,0)=f_y(0,0)=0$, then the locus $f(x,y)=0$ cannot contain a smoothly embedded curve passing through the origin.
A sketch of a proof is as follows: If the origin is not isolated, then $f(z,w)$ is a $\mathbb{C}$-valued analytic function defined on a neighborhood of the origin in $\mathbb{C}^2$ that is also irreducible in this larger ring, and hence there is a neighborhood of the origin in $\mathbb{C}^2$ such that, in this neighborhood, the locus $f(z,w)=0$ can be parametrized by an embedded disc in $\mathbb{C}$ in the form $(z,w) = (a(\tau),b(\tau))$ where $a$ and $b$ are analytic functions of $\tau$ for $|\tau| < 1$ with $a(0)=b(0)=0$. By a (real) rotation, we can assume that $a$ vanishes to a lower order, say $k>1$, than $b$ does. Thus, we can reparametrize in $\tau$ so that $a(\tau) = \tau^k$ for some $k>1$. In particular, the real locus will be parametrized by some curves of the form $\tau = \omega\,t$ where $t$ is real and $\omega^k = \pm 1$. Choosing one such curve and replacing $t$ by $t/\omega$, we can assume that $(a(t),b(t))$ is real for all small real $t$, and that this parametrizes a 'branch' of the real locus that passes through the origin. In particular, the coefficients of $b$ are real, so our curve is parametrized in the form
$$
(x,y) = \bigl(\ t^k,\ b_l t^l + b_{l+1} t^{l+1} + \cdots\ \bigr)
$$
where $l>k$ and, because of the embeddedness property of the disk, the greatest common divisor of $k$ and those $m$ for which $b_m\not=0$ must be $1$. Thus, the curve is expressed in the form
$$
y = b_l\ x^{l/k} + b_{l+1}\ x^{(l+1)/k} + \cdots
$$
where at least one of the exponents in this series is not an integer. It follows that the function on the right hand side of this equation cannot be smooth at $x=0$, even though, since $l>k$, it is $C^1$.
One conclusion of all this is that, if $g$ is a real-valued smooth function on a neighborhood of $0\in \mathbb{R}$ such that $g(0)=0$ and such that there exists a nontrivial real-analytic $f$ defined on a neighborhood of $(0,0)$ such that $f\bigl(x,g(x)\bigr)\equiv0$ for $x$ in the domain of $g$, then $g$ must actually be real-analytic in a neighborhood of $0$. (Note, however, that there do exist such 'real-analytically constrained' $g$ that, for some $m>0$, are $C^m$ but not $C^{m+1}$ at $x=0$.)
Now, an easy argument shows that this $1$-variable fact implies the corresponding $n$-variable fact: If $g$ is a real-valued smooth function on a neighborhood of $0\in \mathbb{R}^n$ such that $g(0)=0$ and such that there exists a nontrivial real-analytic $f$ defined on a neighborhood of $(0,0)\in\mathbb{R}^n\times\mathbb{R}$ such that $f\bigl(x,g(x)\bigr)\equiv0$ for $x$ in the domain of $g$, then $g$ must actually be real-analytic in a neighborhood of $0\in\mathbb{R}^n$. (Basically, the hypotheses and the $1$-variable result imply that $g\circ x$ is real-analytic for any real-analytic germ of a curve $x:(\mathbb{R},0)\to(\mathbb{R}^n,0)$, and this easily implies that $g$ itself is real-analytic in a neighborhood of $0\in\mathbb{R}^n$.)
Thus, we have the answer to the question Suppose that the origin is a singular zero of an irreducible element $f$ in the ring of real-valued analytic functions defined on a neighborhood of the origin. Can the zero locus of $f$ be a nonsingular smooth hypersurface near the origin?
The answer is 'no', because smooth would imply real-analytic, and we have already seen that this cannot happen.
Best Answer
If you're willing to view a variety as a set of points rather than as a scheme, then it is fairly easy to show that every real algebraic variety $V$ in ${\bf R}^n$ is equal as a set to the finite union of smooth manifolds (of various dimensions, and typically not closed). Namely, one can view $V$ as the restriction of some complex variety $V_{{\bf C}} \subset {\bf C}^n$ to ${\bf R}^n$. By decomposing into irreducible components, we may assume without loss of generality that $V_{{\bf C}}$ is irreducible. If $V_{{\bf C}}$ is not invariant with respect to complex conjugation $(z_1,\dots,z_n) \mapsto (\overline{z_1}, \dots, \overline{z_n})$, then one may intersect this variety with its complex conjugate, dropping the dimension of this variety without affecting $V$ as a set. Thus, by an induction on dimension, one may assume that $V_{{\bf C}}$ is invariant with respect to complex conjugation (or equivalently, is definable over the reals). We remove the (complex) singular points of $V_{{\bf C}}$, since these can be handled by the induction on dimension, leaving us with the smooth points of $V_{{\bf C}}$ in ${\bf R}^n$. At such a point, the complex tangent space is invariant with respect to complex conjugation and is thus the complexification of a real space of the same dimension. From this it is easy to see that $V$ is a smooth manifold at this point, and the claim follows.