In A a PID, $d=\gcd(a,b) \iff ax+by=d$ I am aware this is Bézout's identity but I'm trying to prove it using ideals, I have the first half and it goes:
Suppose $ax+by=d$
$ax+by=d \implies d \in (a,b) \implies (a,b)=(d) \implies a,b \in (d) \implies d \mid a \wedge d \mid b$
Now, say there's a $c \in A$ such that $c \mid a \wedge c\mid b$ then $c \mid ax+by \implies c \mid d$
And so by definition we have $d=\gcd(a,b)$
Suppose $\gcd(a,b)=d$
This is where I am lost, I've tried this so far:
$d=\gcd(a,b) \implies d \mid a \wedge d \mid b \implies d \mid ax+by \implies ax+by \in (d)$
This is where I get stuck I want to follow and say that means $(d)=(a,b)$ but I'm not sure I can make that assumption just with that and I'm not using the gcd hypothesis, only that $d$ is a common divisor.
Any input would be helpful. Thank you.
 A: The statement you write is incorrect. While in a PID a gcd can be expressed as a linear combination, it is not true that every linear combination is a gcd.
The first part of your proof is incorrect after the first implication. You are correct that $d=ax+by$ implies $d\in (a,b)$, but your assertion that this implies $(d)=(a,b)$  is unwarranted. You only have $(d)\subseteq (a,b)$. You have not justified the other inclusion (unless you were assuming without stating that $d$ is a common divisor; if so, you need to say so explicitly).
The second part likewise fails in the second implication: from $d|a$ and $d|b$, it is not valid to deduce that $d=ax+by$.  For instance, in $\mathbb{Z}$, $2|8$ and $2|12$, but $2$ cannot be written as a linear combination of $8$ and $12$.

There are a number of ways of fixing the statement. For example:
Theorem. Let $A$ be a PID, and let $a,b,d\in A$. The following are equivalent:

*

*$d=\gcd(a,b)$.

*$(d)=(a,b)$, as ideals.

*There exist $x,y\in A$ such that $d=ax+by$ and for all $s,t\in A$, $d|as+bt$.

*There exist $x,y\in A$ such that $d=ax+by$ and $d$ is a common divisor of $a$ and $b$.

As an aside, (2), (3), and (4) are always equivalent, and imply (1). It is only in the implication from (1) to the rest that you need to use that $A$ is a PID.
Proof. First we show the equivalence of (2), (3), and (4), without using that $A$ is a PID, only that it  is a (commutative) domain.
(2)$\implies$(3) Since $d\in (a,b)$, and every element of $(a,b)$ is of the form $ax+by$ for some $x,y\in A$, we have the first clause of (3). For the second, $as+bt\in (a,b)=(d)$, so there exists $y\in A$ such that $dy=as+bt$, as required.
(3)$\implies$(4): The first clause of (4) is immediate. Taking $s=1$, $t=0$ we get $d|a$. Taking $s=0$, $t=1$ we get $d|b$. This yields the second clause of (4).
(4)$\implies$(2): Because $d=ax+by$, wee have $d\in (a,b)$, hence $(d)\subseteq (a,b)$. Since $d|a$, then $a\in (d)$; since $d|b$, then $b\in (d)$. Therefore, $(a,b)\subseteq (d)$, yielding equality.
Next we show that each of (4) implies (1); again, this does not require that $A$ be a PID:
(4)$\implies$(1):  To show that $d$ is a greatest common divisor of $a$ and $b$, we need to show that it is common divisor and is a multiple of every common divisor. We already know that it is a common divisor. If $r$ is a common divisor of $a$ and $b$, then $r|ax$ and $r|by$, hence $r|ax+by=d$. Thus, $d$ is a gcd of $a$ and $b$.
Finally, using that $A$ is a PID we can go from (1) to the  other statements:
(1)$\implies$(2): Since $A$ is a PID, we know that there exists $r\in A$ such that $(a,b)=(r)$. Since $a,b\in (d)$, then $(r)=(a,b)\subseteq (d)$, so $d|r$.  On the other hand, $a,b\in (r)$, so $r|a$ and $r|b$, hence because $d$ is a gcd of $a$ and $b$ we have $r|d$. Thus, $r|d$ and $d|r$, and $A$ is a domain, so $r$ and $d$ are associates, hence $(d)=(r)=(a,b)$, proving (2). $\Box$
Note that (1)$\implies$(2) does not hold in arbitrary domains (even in UFDs):  in $\mathbb{Z}[x]$, we have that $1=\gcd(2,x)$ (since $2$ and $x$ are non-associate irreducibles), but $1$ cannot be expressed as a $\mathbb{Z}[x]$-linear combination of $2$ and $x$. Domains in which  (1) and (2) are equivalent are called Bézout Domains.
