Chalkline / Guides / State diagram examples

State diagram examples, explained simply

A state diagram shows the situations something can be in and what moves it from one to the next. It is the best way to describe an order, a login, a traffic light or any screen with modes. Here is the notation and three examples.

Updated 7 November 2026 · 3 minute read

What a state diagram is

Many things in software are always in exactly one situation at a time. An order is waiting, paid, shipped or cancelled. A traffic light is red, green or amber. Each situation is a state. An event that moves it to another state is a transition.

A state diagram (also called a state machine diagram or a state chart) draws those states as boxes and the transitions as arrows labelled with the event that causes them. It makes rules such as "you cannot ship an order that is not paid" impossible to miss.

The notation

ElementDrawn asMeans
StateA rounded boxA situation the thing can be in
StartA small filled dotWhere it begins
EndA dot inside a ringWhere it finishes
TransitionAn arrow with a labelThe event that moves it
ChoiceA small diamondThe next state depends on a condition
NoteA sticky noteExtra rules or details

Example 1: an online order

The states of an online orderThe states of an online orderWaitingPaidCancelledShippedDeliveredRefundedpayment receivedcustomer cancelsparcel sentsigned forrefund issued
The states of an online orderOpen this example in Chalkline →

Notice what the diagram makes clear: there is no arrow from Shipped to Cancelled, so once a parcel leaves you cannot cancel. If the business wants that, someone has to add a path.

Example 2: a document review

A document moves from draft to publishedA document moves from draft to publishedDraftInReviewPublishedsubmitapprove
A document moves from draft to publishedOpen this example in Chalkline →

A real review also has a path back: InReview --> Draft : changes requested. Loops like that are normal in state diagrams; a traffic light, for example, is nothing but a loop from red to green to amber and back to red.

Example 3: logging in

A login with a lock after too many triesA login with a lock after too many triesLoggedOutCheckingLoggedInLockedsubmitcorrectfive wrong tries
A login with a lock after too many triesOpen this example in Chalkline →

The full version also sends a wrong password back to LoggedOut, unlocks the account after 15 minutes and lets a user log out. Add those arrows one at a time and check each one is a rule you really want.

Writing a state diagram as text

The examples above use Mermaid's state diagram text, which is short enough to keep in a code comment or a README:

stateDiagram-v2
  [*] --> Waiting
  Waiting --> Paid : payment received
  Paid --> Shipped : parcel sent
  Shipped --> [*]
  state "Waiting for payment" as Waiting
  note right of Paid : Stock is reserved here
  • [*] is the start when it is on the left of the arrow and the end when it is on the right.
  • A --> B : event is a transition with its label.
  • state "Long name" as A gives a short id a readable name.
  • state Check <<choice>> draws a diamond for a decision.

How to draw a good state diagram

  1. List the states as nouns or adjectives: Waiting, Paid, Locked. If a name is a verb, it is probably a transition.
  2. Start with the happy path from start to end.
  3. Add the other events one state at a time: what can happen while it is here?
  4. Look for dead ends: states with no way out that should have one.
  5. Look for missing rules: arrows that should not exist, or ones the business forgot.
Open the text editor on the timeline tabState diagrams are one tab away
Open the example

State diagram vs flowchart

A flowchart shows the steps of a process in order. A state diagram shows the situations one thing can be in and what changes them. If you are describing what a person or program does, use a flowchart. If you are describing what an order, a device or a screen *is* at any moment, use a state diagram.

Drawing state diagrams for free

In Chalkline, open Diagram as text → State, type the transitions and press Apply. Start and end dots, choice diamonds and notes are drawn for you. Switch between hand drawn and clean, export to SVG, PDF or PowerPoint, and keep the text next to your code. For the other diagrams developers use most, see sequence diagrams and UML class diagrams.