What are feature flags?

In short
Feature flags are switches in code that let a team turn a feature on or off without deploying new code. The code for both versions ships together, and a configuration value decides which path runs. Teams use them to release changes safely, test with real users, and compare results.
The basic idea
A feature flag, also called a feature toggle, is a small condition in your code. It checks a value and chooses one of two code paths. One path holds the old behavior and the other holds the new behavior. The flag value can change while the program runs, so you do not need a new build to switch paths.
Martin Fowler's article on feature toggling describes this as a way to deliver new functionality quickly but safely. The same idea goes by several names, including feature bits and feature flippers. You will see all of them in the wild.
How it works
The usual setup has three parts. The first is the toggle point, the place in the code where the decision is made. The second is the toggle router, a piece of code that answers the question "is this feature on?" The third is the toggle configuration, the stored data that the router reads, such as a file, a database, or an admin page.
The router can be very simple, such as a dictionary in memory. It can also be a sophisticated service with a web interface. The key point is that the code asks the router, and the router decides. Changing the answer changes the behavior.
Some routers go further and decide per request. They look at context about the caller, such as a cookie, an HTTP header, or a user ID. This lets a team show a feature to internal staff only, while everyone else still sees the old version.
When to use it
Feature flags fit well when a team wants to keep one shared main branch rather than maintain long-lived branches. Long branches are hard to merge, so keeping unfinished work hidden behind a flag is often easier. Flags also help when a change is risky, because a team can turn it off quickly without rolling back a deployment.
Teams commonly use flags for three purposes. One is releasing code that is not finished yet. Another is a canary release, where a small group of users gets the new feature first. The third is A/B testing, where two groups of users see different versions so the team can compare results.
The article points out that flags do not all behave the same. Some live for days, while others may stay for years. Some change rarely, while others must be decided for every request. Treating every flag the same way can cause problems later.
A simple example
Here is a small sketch of a flag check. The function asks the router whether a feature is enabled, then runs the matching code.
function reticulateSplines() {
if (featureIsEnabled("use-new-SR-algorithm")) {
return enhancedSplineReticulation();
} else {
return oldFashionedSplineReticulation();
}
}
In tests, the team can set the flag to true and then to false. This checks both paths before the feature reaches users. The same flag can later be turned on for a small cohort, then for everyone.
Common mistakes
The biggest risk is leaving old flags in the code forever. Each flag doubles the number of paths the code can take, which makes testing harder. Once a feature is fully released, remove the flag and the old path.
Another mistake is treating all flags as permanent settings. A release flag should be temporary. A flag that controls a business rule may need a longer life, and it deserves more care in how it is managed.
Teams also need to be careful with who sees what. A cohort should stay consistent, so a user does not flip between versions on each visit. If you plan to compare groups, measure the same metrics for both groups.
Alternatives
If a feature is small and the change is safe, a flag may be more work than it is worth. A team can also use separate branches for large, isolated changes, though this brings merge costs. For changes that affect deployment rather than behavior, teams sometimes use gradual rollouts that replace servers in stages. Each option trades off simplicity, speed, and risk, so pick the one that fits the change.
For a broader look at how teams ship code safely, read about continuous delivery on our site once it is available.
FAQ
Are feature flags the same as feature toggles?
Yes. The terms are synonyms, and the article uses them interchangeably. Feature bits and feature flippers are also used for the same technique.
Do feature flags need a special tool?
No. A simple flag can be a value in a config file or a dictionary in memory. Larger teams often use a dedicated service with an admin page, but the core idea needs only a conditional check.
What is a canary release?
A canary release turns a feature on for a small group of users first. The team watches key metrics for that group before enabling the feature for everyone else.
Should old feature flags be removed?
Yes, once the feature is fully rolled out or dropped. Leftover flags add extra code paths that are hard to test and easy to forget.
Sources
This page is based on the official documentation below. Read it for full detail.
Feature flags — official documentation ↗