An algorithm is a finite, ordered set of well-defined steps that takes an input and produces an output, solving a problem or completing a task. Computers run on algorithms, but the idea is older than computing: long division and a recipe are both algorithms. In finance, algorithms decide which card payments look fraudulent, set prices, route orders to markets and, in crypto, decide which blocks join a blockchain.
The word comes from the name of the ninth-century Baghdad mathematician Muhammad ibn Musa al-Khwarizmi, whose works on arithmetic were translated into Latin under a title beginning "Algoritmi". In modern usage an algorithm is distinct from a program: the algorithm is the method, and a program is one way of writing it down in a particular language. The term is also used loosely in the press for any automated decision system, including machine-learning models.
Algorithm in plain terms
An algorithm is a set of instructions precise enough that anyone, or any machine, following them gets the same result. Directions such as "turn left at the bakery, then take the second right" are an algorithm for reaching a friend's house. If the steps are vague ("go roughly north for a while"), it stops being one.
Good algorithms are also efficient. Two sets of directions might both reach the house, but one takes five minutes and the other an hour. Much of computer science is about finding steps that get the right answer with as little time and effort as possible.
Properties of an algorithm
Textbook definitions usually require an algorithm to have these features:
- Finiteness. It must finish after a limited number of steps.
- Definiteness. Each step must be exact, with no room for interpretation.
- Input and output. It takes zero or more inputs and produces at least one result.
- Effectiveness. Each step must be basic enough to be carried out in practice.
Euclid's method for the greatest common divisor of two numbers, written down around 300 BC, is often cited as one of the oldest algorithms still in use. In the 1930s Alan Turing and others gave the idea a formal mathematical basis, which led to the concept of a Turing-complete machine able to run any algorithm.
Algorithms in payments and banking
Everyday financial infrastructure depends on simple, published algorithms:
- Check digits. The Luhn algorithm, patented by IBM engineer Hans Peter Luhn in 1960, catches most typing errors in card numbers. IBANs use a similar check based on dividing by 97.
- Encryption and signatures. Encryption and digital signatures protect card data and payment messages, and one-time passwords are generated by algorithms shared between a bank and a device.
- Fraud and risk scoring. Banks run rules and statistical models over every transaction for fraud detection, and lenders use scoring algorithms to produce a credit score.
- Settlement and netting. Clearing houses use algorithms to net obligations between banks before settlement.
Algorithms in markets
Algorithmic trading uses programs to decide when, where and how much to buy or sell. Strategies range from splitting a large order into small pieces to reduce market impact, to high-frequency trading that reacts in microseconds. An exchange's matching engine is itself an algorithm that pairs orders on the order book, usually by price and then by time of arrival.
Failures show the stakes. On 1 August 2012, faulty trading software at Knight Capital sent erroneous orders that cost the firm about $440 million in under an hour. Crypto markets have their own automated players, from crypto trading bots to the sniper bots that buy new tokens the moment they list.
Algorithms in crypto
Blockchains are built from algorithms. Three families matter most:
- Hashing. A hash algorithm such as SHA256 turns any data into a fixed-length fingerprint; Bitcoin uses it to link blocks and in mining.
- Consensus. A consensus algorithm lets thousands of computers agree on one history. Proof of work and proof of stake are the best known.
- Monetary rules. Bitcoin's supply schedule and its difficulty adjustment are algorithms written into the protocol, not decisions taken by a committee.
The word also appears in token names and designs. An algorithmic coin or algorithmic stablecoin tries to hold a price through programmed supply changes rather than reserves; the collapse of TerraUSD in May 2022 showed how such rules can fail under stress. In DeFi, a smart contract such as an automated market maker prices trades with a fixed formula.
Limitations and oversight
An algorithm is only as good as its design and data. Errors can spread at machine speed, models trained on biased data can treat customers unfairly, and complex systems can be hard to explain to regulators or customers. Financial regulators therefore expect firms to test, document and monitor algorithms used in trading and credit decisions, and to keep humans able to intervene.