Essentially, each party agrees:
on a public value g and a large prime number p .
one party chooses a secret value x
the other party chooses a secret value y
Both parties use their secret values to derive public values, g x mod p and g y mod p,
they exchange the public values.
Each uses the other party's public value to calculate the shared secret key that is used by both parties for confidential communications.
A third party cannot, in theory, derive the shared secret key because they do not know either of the secret values, x or y .
For Example:
Alice chooses secret value x and sends the public value g x mod p to Bob.
Bob chooses secret value y and sends the public value g y mod p to Alice.
Alice uses the value g xy mod p as her secret key for confidential communications with Bob.
Bob uses the value g yx mod p as his secret key.