Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • System Design Tutorial
  • What is System Design
  • System Design Life Cycle
  • High Level Design HLD
  • Low Level Design LLD
  • Design Patterns
  • UML Diagrams
  • System Design Interview Guide
  • Scalability
  • Databases
Open In App
Next Article:
State Machine Diagrams | Unified Modeling Language (UML)
Next article icon

State Machine Diagrams | Unified Modeling Language (UML)

Last Updated : 08 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A State Machine Diagram is used to represent the condition of the system or part of the system at finite instances of time. It’s a behavioral diagram and it represents the behaviour using finite state transitions. In this article, we will explain what is a state machine diagram, the components, and the use cases of the state machine diagram.

state-machine-diagram-banner

Table of Content

  • What is a State Machine Diagram?
  • Basic components and notations of a State Machine diagram
  • UseCases of State Machine Diagram
  • What are the Differences between a State Machine Diagram and a Flowchart?

What is a State Machine Diagram?

A State diagram is a UML diagram which is used to represent the condition of the system or part of the system at finite instances of time. It’s a behavioral diagram and it represents the behavior using finite state transitions.

  • State Machine diagrams are also known as State Diagrams and State-Chart Diagrams. These both terms can be used interchangeably.
  • A state machine diagram is used to model the dynamic behaviour of a class in response to time and changing external stimuli( events that cause the system to change its state from one to another).
  • We can say that every class has a state but we don't model every class using State Machine diagrams.

Let's understand the State Machine Diagram with the help user verification example:

Example:


A-State-Machine-Diagram-for-user-verification

The State Machine Diagram above shows the different states in which the verification sub-system or class exists for a particular system.

Basic Components and Notations of a State Machine Diagram

Below are the basic components and their notations of a State Machine Diagram:

1. Initial state

We use a black filled circle represent the initial state of a System or a Class.

initial-State-(1)

2. Transition

We use a solid arrow to represent the transition or change of control from one state to another. The arrow is labelled with the event which causes the change in state.

transition

3. State

We use a rounded rectangle to represent a state. A state represents the conditions or circumstances of an object of a class at an instant of time.

state

4. Fork

We use a rounded solid rectangular bar to represent a Fork notation with incoming arrow from the parent state and outgoing arrows towards the newly created states. We use the fork notation to represent a state splitting into two or more concurrent states.

fork-(1)

5. Join

We use a rounded solid rectangular bar to represent a Join notation with incoming arrows from the joining states and outgoing arrow towards the common goal state. We use the join notation when two or more states concurrently converge into one on the occurrence of an event or events.

join-(1)

6. Self transition

We use a solid arrow pointing back to the state itself to represent a self transition. There might be scenarios when the state of the object does not change upon the occurrence of an event. We use self transitions to represent such cases.

self-transition

7. Composite state

We use a rounded rectangle to represent a composite state also. We represent a state with internal activities using a composite state.

composite-state

8. Final State

We use a filled circle within a circle notation to represent the final state in a state machine diagram.

final-state-(1)

How to draw a State Machine diagram in UML?

Below are the steps on how to draw the State Machine Diagram in UML:

State-Machine-Diagrams-Unified-Modeling-Language-(UML)

Step 1: Identify the System:

  • Understand what your diagram is representing.
  • Whether it's a machine, a process, or any object, know what different situations or conditions it might go through.

Step 2: Identify Initial and Final States:

  • Figure out where your system starts (initial state) and where it ends (final state).
  • These are like the beginning and the end points of your system's journey.

Step 3: Identify Possible States:

  • Think about all the different situations your system can be in.
  • These are like the various phases or conditions it experiences.
  • Use boundary values to guide you in defining these states.

Step 4: Label Triggering Events:

  • Understand what causes your system to move from one state to another.
  • These causes or conditions are the events.
  • Label each transition with what makes it happen.

Step 5: Draw the Diagram with appropriate notations:

  • Now, take all this information and draw it out.
  • Use rectangles for states, arrows for transitions, and circles or rounded rectangles for initial and final states.
  • Be sure to connect everything in a way that makes sense.

Example: Online Order System

Let's understand State Machine diagram with the help of an example, ie for an Online Order :
state-machine-diagram-for-an-online-order

The UML diagrams we draw depend on the system we aim to represent. Here is just an example of how an online ordering system might look like :

  • On the event of an order being received, we transition from our initial state to Unprocessed order state.
  • The unprocessed order is then checked.
  • If the order is rejected, we transition to the Rejected Order state.
  • If the order is accepted and we have the items available we transition to the fulfilled order state.
  • However if the items are not available we transition to the Pending Order state.
  • After the order is fulfilled, we transition to the final state. In this example, we merge the two states i.e. Fulfilled order and Rejected order into one final state.

Note: Here we could have also treated fulfilled order and rejected order as final states separately.

Applications of State Machine Diagram

Below are the main use cases of state machine diagram:

  • State Machine Diagrams are very useful for modeling and visualizing the dynamic behavior of a system.
  • They are also used in UI design where they help to illustrate how the interface changes in response to user actions, helping designers to create a better use experience.
  • In game design, state machine diagrams can help model the behavior of characters or objects, detailing how they change states based on player interactions or game events
  • In embedded systems, where hardware interacts with software to perform tasks, State Machine Diagrams are valuable for representing the control logic and behavior of the system.

What are the Differences between a State Machine Diagram and a Flowchart?

Before understanding the differences between a state machine diagram and a flowchart, firstly understand what is a flowchart:

What is a Flowchart?

An algorithm is like a set of clear instructions to solve a problem, and a flowchart is a picture that shows those instructions.

  • When we're writing computer programs, a flowchart helps us map out the steps of the algorithm to solve the problem.
  • Non programmers use Flow charts to model workflows.
  • We can call a flowchart a primitive version of an activity diagram.
  • Business processes where decision making is involved is expressed using a flow chart.

Example:

A manufacturer uses a flow chart to explain and illustrate how a particular product is manufactured.

State Machine Diagram vs. Flow Chart?

Below are the main differences between a state machine diagram and a flowchart:

State Machine Diagram

Flow Chart

An State Machine Diagram is associated with the UML(Unified Modelling Language)

A Flow Chart is associated with the programming.

The basic purpose of a state machine diagram is to portray various changes in state of the class and not the processes or commands causing the changes.

A flowchart on the other hand portrays the processes or commands that on execution change the state of class or an object of the class.

Primarily used for systems, emphasizing their states and transitions.

Often used for processes, procedures, or algorithms involving actions and decisions.

Conclusion

State Machine Diagrams in UML are like pictures that tell us how things change in a system. They show the different situations a system can be in and how it moves between them. These diagrams help us understand what events make these changes happen. Whether it's for designing software or explaining how something works, State Machine Diagrams are like visual guides that make it easier to see and understand how a system behaves in different situations.


Next Article
State Machine Diagrams | Unified Modeling Language (UML)

A

Ankit Jain
Improve
Article Tags :
  • Design Pattern
  • System Design
  • UML

Similar Reads

    What are UML Diagrams

    Unified Modeling Language (UML) Diagrams
    Unified Modeling Language (UML) is a general-purpose modeling language. The main aim of UML is to define a standard way to visualize the way a system has been designed. It is quite similar to blueprints used in other fields of engineering. UML is not a programming language, it is rather a visual lan
    14 min read
    UML Full Form
    The full form of UML is "Unified Modeling Language". It is a general-purpose modeling language. The main aim of UML is to define a standard way to visualize how a system has been designed. It is quite similar to blueprints used in other fields of engineering. UML is not a programming language, it is
    3 min read

    Structural Diagrams

    Class Diagram | Unified Modeling Language (UML)
    A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a project—like developers and designers—understand how the system is organized and how its components interact
    12 min read
    Object Diagrams | Unified Modeling Language (UML)
    Object diagrams are a visual representation in UML (Unified Modeling Language) that illustrates the instances of classes and their relationships within a system at a specific point in time. They display objects, their attributes, and the links between them, providing a snapshot of the system's struc
    8 min read
    Deployment Diagram in Unified Modeling Language(UML)
    A Deployment Diagram is a type of Structural UML Diagram that shows the physical deployment of software components on hardware nodes. It illustrates the mapping of software components onto the physical resources of a system, such as servers, processors, storage devices, and network infrastructure.Ta
    8 min read
    Package Diagram – Unified Modeling Language (UML)
    A package diagram is a type of structural diagram in UML (Unified Modeling Language) that organizes and groups related classes and components into packages. It visually represents the dependencies and relationships between these packages, helping to illustrate how different parts of a system interac
    7 min read

    Behavioral Diagrams

    Behavioral Diagrams | Unified Modeling Language(UML)
    Complex applications need collaboration and planning from multiple teams and hence require a clear and concise way to communicate amongst them. So UML becomes essential to communicate with non-programmers about essential requirements, functionalities, and processes of the system. UML is linked with
    7 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences