Flash Loans and Arbitrage in DeFi

Flash loans let you borrow millions with zero collateral for one atomic transaction. How DeFi arbitrage works, what gas and slippage really cost

TRADING & RISK5 min readBy AlgoSys Editorial TeamPublished Apr 25, 2026Updated Jun 26, 2026
Contents

A flash loan is arguably the most unusual instrument in decentralized finance (DeFi, financial services without banks or intermediaries, built on smart contracts). It lets you borrow any available volume of cryptocurrency with no collateral at all, but with one hard condition: everything must be returned within the very same blockchain transaction in which you borrowed. If you do not return it, the loan is treated as if it was never issued.

It sounds like a trick, and that is essentially what it is. Traders use flash loans for arbitrage (profiting from price differences between venues), collateral swaps, and complex multi-step strategies that would require large capital on hand in conventional finance. For an intermediate trader, this is a door into advanced DeFi operations and sources of profit that simply do not exist in traditional finance.

The main advantage here is capital efficiency. You do not need your own reserves to execute a million-dollar trade: you borrow that million for a fraction of a second, exploit the market inefficiency, return the loan, and keep the difference.

MECHANICS

A flash loan is executed as a single atomic transaction (atomic: indivisible, either everything goes through entirely or nothing happens at all). The borrower takes funds from a lending protocol and immediately puts them to work, for example in an arbitrage trade between two decentralized exchanges (DEX). The profit from that operation, minus a small protocol fee (usually 0.09% to 0.3%), goes toward repaying the principal and the fee itself.

The entire reliability of the scheme rests on this atomicity. If the loan is not repaid by the end of the transaction, the blockchain rolls it back completely: the funds have gone nowhere, there was technically no loan, and there are no losses (other than the gas already paid). The lender is therefore guaranteed to get the money back, and the borrower ends up in profit only if the strategy worked profitably within that same transaction.

Let's walk through the numbers. A trader borrows 1,000 ETH. On DEX A they buy ETH at $3,000, and on DEX B they immediately sell it at $3,005. The $5 difference per ETH yields a gross profit of $5,000. The protocol fee of 0.1% on 1,000 ETH comes to roughly $100. After subtracting it, the net profit of $4,900 together with the principal is returned to the lending protocol, and the earnings stay with the trader. If the prices had converged and the spread disappeared before the sale, the transaction would simply have rolled back, and the trader would have lost only the gas.

EXECUTION

In practice, a flash loan is not a button but a pre-written smart contract that carries out the entire chain of actions in a single call. Time sensitivity is critical: the opportunity lives only until the next block. A typical scenario looks like this:

  1. Find a profitable arbitrage spread between two or more DEXes.
  2. Choose a DeFi lending protocol that offers flash loans and a suitable audited smart contract (your own or a ready-made one) that automates the "borrow, trade, repay" cycle.
  3. Calculate the exact loan amount based on the spread size and the available liquidity on both venues.
  4. Launch the contract: it takes the flash loan, immediately executes the arbitrage trades, returns the principal plus the protocol fee, and transfers the remaining profit to your wallet.

If anything does not add up at any of these steps (the spread disappeared, liquidity was insufficient, the calculation did not close in profit), the entire transaction rolls back, and the profit transfer simply never happens.

COMMON MISTAKES

The most common beginner mistake is underestimating gas fees (gas, the network's payment for computation). Complex interactions with smart contracts are expensive, and on narrow spreads gas can completely eat up all the arbitrage profit. Always factor in a gas estimate when calculating the potential P&L (profit and loss) before launching the contract.

The second trap is insufficient liquidity on one of the venues. If the market is too "thin" and the entire loan volume cannot be filled at the expected price, the arbitrage does not work. In the best case the transaction rolls back; in the worst case (with partial execution) you end up with a loss. Before launching, confirm that market depth is sufficient for the full trade volume, not just its beginning.

And finally, the security of the contract itself. Unverified or poorly audited code through which a flash loan passes exposes capital to exploits (exploit, an attack through a vulnerability). Work only with reputable protocols and audited contracts so that the profit-making instrument does not become a backdoor for an attacker.

RISK MANAGEMENT

Flash loans require no collateral, but that does not mean they are risk-free. The main risk is that the strategy does not close in profit within a single transaction: the trade rolls back, but the gas has already been paid. To keep such misfires from hitting your wallet, size your strategy so that the maximum gas cost does not exceed 1% of the borrowed capital. On a large loan, the fixed gas cost becomes a negligible fraction, and that works in your favor.

Direct liquidation (the forced closure of a position at a loss), as in margin trading, does not exist here thanks to atomicity. But the risk of a smart contract failure or exploit is significant. The contract logic is worth thoroughly testing and auditing, and the volume of capital in any single flash strategy should be kept at a level that would not put the entire portfolio at risk if something goes wrong.

Keep slippage (the deviation of the actual price from the expected one) in mind separately. If the market moves between when you spotted the opportunity and when the contract executes it, the price may have shifted against you. Model the worst-case scenario in advance and only take strategies where even a 0.5% unfavorable price movement still allows the loan and the fee to be repaid.

How to tell a real opportunity from a false one: a genuine arbitrage spread survives the deduction of gas, the protocol fee (0.09-0.3%), and a 0.5% slippage buffer and still comes out positive. If profit disappears after any of these deductions or holds up on adequate liquidity only for part of the volume, that is a false signal, and the contract should not be launched.

FAQ

What are flash loans actually used for?

Most often they are taken out for arbitrage, meaning profiting from price differences for the same asset across different decentralized exchanges. They are also useful for collateral swaps, debt refinancing, and complex multi-step DeFi strategies where large capital is needed for a brief moment that the trader does not have on hand.

Is it true that a flash loan requires no collateral?

Yes, and that is its defining feature. No collateral is required because the loan is guaranteed to be repaid within the same atomic transaction in which it was issued. If repayment does not occur, the blockchain rolls back the entire transaction, and the lender risks nothing.

What are the main risks of flash loans?

There are three. High gas fees can eat up all of the arbitrage profit on narrow spreads. Insufficient liquidity on a venue can derail the execution of the full volume. And vulnerabilities in the smart contract expose capital to exploits. These risks are reduced by careful gas estimation, checking market depth, and working only with audited code.

Can you lose the borrowed funds if the strategy does not work?

You cannot lose the borrowed funds themselves: if the attempt fails, the transaction is rolled back as if the loan never happened. But the gas already paid for the attempt will not be refunded. So keep gas costs within 1% of the loan size to prevent a series of failed attempts from accumulating into a meaningful loss.

Do you need to know how to code to use flash loans?

In one form or another, yes. A flash loan is executed through a smart contract that automates the entire "borrow, trade, repay" chain in a single call. You can write the contract yourself or use a ready-made one, but in either case you need to understand its logic and trust only verified, audited code.

How do you know whether an arbitrage opportunity is real or false?

Calculate the profit after all deductions: gas, the protocol fee (0.09-0.3%), and a slippage buffer of around 0.5%. If the spread is still positive after that and there is enough liquidity for the entire trade volume, the opportunity is viable. If profit disappears on any of those deductions, it is a false signal.

Put this to work in the terminal

Live charts, derivatives, on-chain and macro data, free.

Open terminal →