XDRIPACADEMY
Sign in

Lessons·DeFi basics·7 min·Beginner

What a DEX is, in 5 minutes

A decentralized exchange is not "a website where you trade crypto." It is a smart contract that sits between you and other liquidity providers, with no order book and no human in the middle. We unpack the difference.


The first DeFi tool most people use is a decentralized exchange, usually called a DEX. The word "exchange" is unfortunately misleading, because most people picture something that looks like a stock exchange: an order book, brokers, market makers, a clearinghouse. A DEX is none of those things. It is something stranger and, once you understand it, more interesting.

This is the short version of what a DEX actually is, why it works, and where the trade-offs live.

What a DEX is not

The mental model most beginners arrive with: a DEX is "Coinbase but decentralized." Two parties want to trade. The DEX matches them. The DEX takes a fee. Done.

That is not how the most common DEXs work.

There is no order book. There are no buyers and sellers being matched to each other. There is no human, or even a piece of software impersonating a human, deciding what price the trade clears at. The DEX is a smart contract, sitting on chain, with a pool of two (or sometimes more) tokens inside it, and a piece of math that determines what happens when you put one in and ask for the other.

The math is the entire mechanism. The pool, the math, and your transaction. Nothing else.

Key takeaway

A typical DEX is not a market between buyers and sellers. It is a smart contract holding a pool of tokens, with a piece of math that determines the exchange rate. You trade with the pool, not with another person.

The mechanism, in plain terms

The most common DEX design is called an automated market maker, or AMM. It works like this.

Imagine a vending machine that holds two kinds of coins, A and B. Inside the machine is a fixed quantity of each. The machine has one rule: the product of how many A's it holds and how many B's it holds must stay roughly constant. If you put coins of type A into the machine, you can take out coins of type B, but the machine will only give you a quantity of B that keeps the product constant.

Suppose the machine has 100 A-coins and 100 B-coins inside. The product is 10,000. You put in 10 A-coins. Now the machine has 110 A-coins. To keep the product at 10,000, it must have about 90.9 B-coins. So it gives you back 9.1 B-coins.

You traded 10 A for 9.1 B. The exchange rate emerged from the math, automatically, without anyone deciding it. The machine adjusted its prices in response to your trade: there are fewer B-coins inside now, so B is "scarcer" relative to A, so the next trade in this direction will get even fewer B's per A.

This is, in simplified form, how a constant-product AMM works. The vending machine is a smart contract. The two stacks of coins are the liquidity pool. The math is the price discovery mechanism. There is no order book and no counterparty in the human sense.

Where the liquidity comes from

The pool inside the smart contract has to come from somewhere. It comes from liquidity providers (LPs). These are users who deposit equal-value amounts of both tokens into the pool, in exchange for a share of the trading fees the pool generates.

Anyone with the two tokens can become an LP. They are not employees of the exchange. The exchange has no employees. They are users with their own self-interested reason to participate: a share of fees, in exchange for putting their tokens into the pool.

The total liquidity in the pool determines how much trading the pool can absorb without prices moving sharply. A small pool with $10,000 in it can be moved by a few hundred dollars of trading. A large pool with $100 million in it absorbs much more before prices shift.

This is why "depth" matters in DEX trading. A large pool is a stable place to trade. A small pool is a volatile place to trade.

Slippage, in one sentence

The price you actually get on a DEX trade is almost never exactly the displayed price.

The displayed price is the rate the pool is currently at. Your trade itself moves the pool, which means by the time your trade is done, the rate has shifted. The difference between the displayed price and the rate you actually got is called slippage, and it is bigger for larger trades and smaller pools.

DEX interfaces let you set a maximum slippage tolerance. If the trade would clear at a rate worse than that tolerance, the transaction reverts. This protects you from being filled at a wildly different rate than you expected, especially in pools where someone else's trade lands between when you sent yours and when it confirms.

For small trades in deep pools, slippage is negligible. For large trades in shallow pools, it can dominate the economics of the trade.

Gas, fees, and the actual cost of a swap

Every DEX trade is an on-chain transaction, which means it pays gas. The gas cost depends on the chain and on network congestion at the moment of the trade. On some chains, gas is a few cents; on others, it can be tens of dollars or more for a single swap.

On top of gas, the pool itself charges a trading fee. This is what the liquidity providers earn. Typical fees range from 0.05% to 1% of the trade, depending on the pool and the protocol.

The total cost of a DEX trade is roughly: the gas, plus the protocol fee, plus the slippage. For a small holder making small trades on an expensive chain, those costs can be substantial relative to the trade size. For larger trades on lower-fee chains, the cost as a percentage drops sharply.

This is why DEX users pay attention to which chain they are on. The same swap can be efficient on one chain and uneconomical on another.

Worth noticing

The phrase "MEV" or "front-running" appears often in DEX discussions. Briefly: because transactions in the mempool are visible before they are confirmed, sophisticated bots can spot a profitable trade you are about to make and execute one ahead of you, often hurting your fill. Modern DEX interfaces and chains have various defenses (private transaction routing, batch auctions, MEV-aware sequencing), but the issue is real and worth being aware of for larger trades. For most small swaps, MEV is a minor effect; for large or sensitive trades, the choice of DEX and routing layer matters.

When to use a DEX vs an exchange

A working rule of thumb. DEXs are best when you want:

  1. Self-custody throughout the trade. The funds never leave your wallet's control; they go into the smart contract briefly and the new tokens come back.
  2. Access to tokens that are not listed on any centralized exchange. Many real assets and projects are only on DEXs.
  3. Permissionless access. No KYC, no waiting, no account creation; just connect a wallet and trade.

Centralized exchanges are usually better when you want:

  1. Lowest possible cost on a specific trade, especially for large amounts where DEX slippage would dominate.
  2. Access to fiat on-ramps and off-ramps.
  3. Specific products (margin, certain derivatives, advanced order types).
  4. The cleanest user experience, especially for people new to crypto.

Most active crypto users use both, for different parts of their workflow. The DEX is a tool. The exchange is a tool. Each has a job it does well.

The bigger picture

A DEX is one example of a broader pattern in DeFi: replacing a financial intermediary with a smart contract. The contract has a defined behavior, encoded in code, executed automatically. There is no human in the middle. The contract is auditable by anyone, runs on the chain, and operates the same way for every participant.

The same pattern applies to lending protocols (deposit your tokens, earn interest from borrowers), to derivatives (open positions through smart-contract-managed margin), to structured products (yield strategies coded into contracts). Each of these is a domain we will cover when this academy expands into deeper DeFi material. The DEX is the introductory case because it is the simplest and most common.

For now: when you use a DEX, you are not trading with another person. You are trading with a piece of math that holds a pool of tokens. The math is fair, in the sense that it does not care who you are. It is also unforgiving, in the sense that bad inputs (large trades into shallow pools, sloppy slippage settings, ignoring gas costs) produce bad outcomes that no human at the exchange will refund.

Use it accordingly.

Key takeaway

A typical DEX is a smart contract holding a pool of two tokens, with a piece of math that determines the exchange rate. You trade with the pool, not a counterparty. Slippage happens because your trade moves the pool. Total cost is gas plus protocol fee plus slippage. The pattern (replace an intermediary with a smart contract) is one of the foundational moves of DeFi, and the DEX is the simplest version of it.

Track your progress

Create a free account to mark lessons complete and unlock pillar discounts.