Overview
expand replaces each tab character with enough spaces to reach the next tab stop, which is every 8 columns by default. Use it when text with tabs must look the same everywhere, for example in a plain-text report or when pasting into a program that treats tabs strangely. The reverse is unexpand.
Background
The expand utility first appeared in 1BSD, according to the macOS manual, which also says expand and unexpand conform to POSIX.1-2001. Today the name covers GNU expand, the expand that macOS ships, and the expand applet in BusyBox. They agree on -t for the tab width.
Examples
Convert a tab to spaces with the default width of 8 columns:
printf 'a\tb\n' | expand
Use a tab stop every 4 columns with -t:
printf 'a\tb\n' | expand -t 4
Check that no tab is left, by looking for the \t that od -c prints for a tab:
printf 'a\tb\n' | expand | od -c | grep -q '\\t' || echo no tabs left
Convert a file, writing the result to a new one:
printf 'x\ty\n' > in.txt && expand in.txt > out.txt && cat out.txt
Options
-t
Set the distance between tab stops, in columns, as in -t 4.
Common mistakes
A tab moves to the next tab stop, not a fixed number of spaces, so a<TAB>b and abcdefg<TAB>b produce different amounts of space. expand reads a file and writes to standard output; it does not change the file in place. In a Makefile a tab is required, so never run expand on one.
Portability
Only -t with one number is in the Common examples. GNU also accepts a list of stops and -i to change only leading tabs, which is not in every implementation. The Common examples were executed on GNU coreutils 9.11, macOS system tools, and BusyBox 1.37.0 (see the development guide for the exact check).
About BusyBox expand
BusyBox bundles expand as an applet, and anything beyond the common options depends on how it was built. This page's examples ran on BusyBox 1.37.0.
BusyBox notes
BusyBox expand supports -t. -i and the list form of -t depend on the build.
References
Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.