What Is Category Theory? Math About Math

Sets, numbers, and computer types have almost nothing in common. Category theory noticed they all obey the same three rules, and built an entire field around the rules instead of the things.

By Petrus Sheya

August 1, 2026 · 6 min read

What do a bag of fruit, the number 5, and a line of code have in common?

Nothing, if you look at what they're made of. A fruit is a fruit, a number is a quantity, a line of code is an instruction. But zoom out far enough and something strange happens: they all live inside worlds that behave exactly the same way.

Each world has "things" in it. Each world has "arrows" connecting some of those things to others. And in every single one of these worlds, you can chain two arrows into a third, and there's always an arrow that does nothing at all.

That's it. That's the whole pattern. Category theory is the study of that pattern, not any one version of it. It's math about math, grammar instead of vocabulary.


Same grammar, different vocabulary

Think about grammar for a second. English, French, and Japanese are wildly different languages. Different words, different sounds, different alphabets. But they all have nouns, they all have verbs, and a verb always connects a subject to something else.

Category theory found the same thing hiding inside math. It calls the "nouns" objects and the "verbs" arrows (mathematicians also say morphisms). A category is just: a bunch of objects, some arrows between them, and two rules about how those arrows behave.

Try it below. Same diagram, three different mathematical languages.

Same three dots, same two arrows, three completely different mathematical worlds. Switch worlds and watch only the labels change.

f: send fruit → shapeg: send shape → checkg∘fA{🍎, 🍊}B{🔵, 🔺}C{✓}
Objects aresets
Arrows arefunctions
Composition holds

Notice what didn't change: there are still three objects, still two arrows, and the arrows still chain together. Only the meaning of the dots and lines changed. That's the entire insight of category theory in one picture.


Chaining arrows: composition

But how do the arrows actually combine? Take an arrow ff from AA to BB, and an arrow gg from BB to CC. Follow ff, land at BB, then follow gg. You end up at CC, and you can also describe that whole trip as a single arrow straight from AA to CC.

We write this new arrow as gfg \circ f, read "gg after ff." This gluing-arrows-together operation is called composition, and it's the main event in category theory. Everything else is commentary.

Now here's a question worth sitting with: if you have three arrows in a row, does it matter which pair you glue first?

Slide through the steps to watch f, then g, then h chain into a single arrow. Toggle the grouping, the resulting arrow never moves.

ABCD
Composite so farf
TypeA → B
Arrows composed1

Slide through the steps and you'll see ff, then gfg \circ f, then the full chain h(gf)h \circ (g \circ f). Now flip the grouping toggle. The arrow doesn't move. Whether you glue gg and ff first, or hh and gg first, you land on the exact same arrow from AA to DD. We write this as:

(hg)f=h(gf)(h \circ g) \circ f = h \circ (g \circ f)

This property is called associativity, and it's one of the two rules every category must obey. Grouping is bookkeeping. The destination never cares how you got there.


The arrow that does nothing

Every object also needs a special arrow, one that loops back to itself and changes nothing when you compose with it. We call it the identity arrow, written idA\text{id}_A for the identity on object AA.

Sounds pointless, right? An arrow that does nothing. But watch what happens when you send a traveler through it.

Pick a route for the traveling dot. Looping through an identity arrow adds distance traveled, never changes where you end up.

id_Aid_BfAB
Distance traveled4.67
Net displacement (A→B)4.67
Resultf, always

Pick "fidAf \circ \text{id}_A" or "idBf\text{id}_B \circ f" and hit play. The dot takes a longer road, looping through the identity arrow first. But it always lands exactly where ff alone would've taken it. More steps, same destination. That's the second rule every category must satisfy:

fidA=f=idBff \circ \text{id}_A = f = \text{id}_B \circ f

Identity arrows are the "do nothing" element, the same role 00 plays in addition or 11 plays in multiplication. You can always detour through one, and it never changes your answer.


Translating between categories

Once you have categories, a natural question shows up: can you map one category into another, in a way that respects all this structure? Not just object to object, but arrow to arrow, and composition to composition?

Yes, and that map has a name: a functor. Think of it as a translator between two languages that preserves the grammar. If FF is a functor from category CC to category DD, it sends every object AA in CC to some object F(A)F(A) in DD, and every arrow ff to some arrow F(f)F(f), without breaking anything.

A functor F translates category C into category D. Slide through the reveal, or hover a node to see its image light up on the other side.

category Ccategory DABCA'B'C'
Objects mapped0/3
Arrows mapped0/2
F(g∘f) = F(g)∘F(f)

Slide through the reveal and watch the translation build up, piece by piece. Hover any object on either side and its partner lights up. By the last step, you can check the one rule that makes this a real functor and not just a random relabeling:

F(gf)=F(g)F(f)F(g \circ f) = F(g) \circ F(f)

The translated composite equals the composite of the translations. Compose first then translate, or translate first then compose, same result either way. That's what "structure-preserving" actually means.


Math about math

Here's the part that gives category theory its name. Categories themselves, the sets-and-functions one, the numbers-and-≤ one, the types-and-code one, can all be treated as objects. And functors between categories act as arrows between those objects.

Which means: the collection of all categories is itself a category. Mathematicians call it Cat\mathbf{Cat}. You can compose functors the same way you compose ordinary arrows, and there's an identity functor that does nothing, same two rules, same pattern, one level up.

This is why people call category theory "math about math." It's not a theory of numbers, or shapes, or equations. It's a theory of the pattern that shows up whenever mathematicians build a world of things and the maps between them. Once you see it in one place, you start seeing it everywhere, groups, topological spaces, databases, even parts of programming languages.


The short version

A category is just objects, arrows between them, a way to chain arrows called composition, and a do-nothing arrow for every object. Composition doesn't care how you group it. Identity arrows are detours that change nothing. A functor is a translator between two categories that respects all of it. And because categories and functors form their own category, category theory ends up studying itself, which is exactly why it earns the name math about math.

The next time you notice the same pattern showing up in sets, numbers, and code, that's not a coincidence. That's category theory, quietly running underneath.


All visualizations are interactive React components running entirely in your browser, built with plain SVG. The composition and functor demos use exact coordinate geometry, no external charting libraries.