Back to Writing

How I built a 5G Core

ascii-art-5g-core

The project referenced throughout this post can be found on Github here.


Shortly after joining a telecom company, I thought to myself: "How hard can it be to make this 5G thing from scratch?". Let's ask gemini:

gemini-5g-core-estimates

This problem being labeled as 'impossible' and 'requires a team' intrigued me even more. I love solving problems that people think are impossible.

But why do people assume it's impossible?

The telecom industry used to be the peak of engineering innovation. Today, much of it is dominated by legacy vendors selling seven-figure “black box” systems that move at a fraction of the speed of modern software.

For decades, we’ve assumed that mobile cores require fancy company materials and contracts. I wanted to put that belief to the test.

In about a month of coding outside of work hours, I built a functional 5G mobile core capable of handling real Cell Phone attachment flows.

This post is about showing how much of the perceived barrier is artificial.


What is a 5G Core?

A 5G network consists of three main components:

Component Description
UE (User Equipment) Your phone or device requesting connectivity.
gNB (gNodeB) The 5G radio tower that handles wireless transmission.
Core The backend system that authenticates users, manages sessions, and routes traffic to the internet.

When you connect to 5G, the UE connects to the best gNB in its radius, and the gNB uses the mobile core to validate your SIM, assign you an IP address, and enforce quality-of-service policies, among many other things. It's the brain of the network.

5g-core-whimsical

The Cost Gap Didn't Make Sense

Production-ready mobile cores typically cost six to seven figures per year. If you’re running an MVNO, you’re likely paying millions per year just to access one.

What surprised me was how little technical justification there was for the price. After digging into 5G architecture, I realized something important:

The entirety of 5G core behavior is defined in open standards.

There is no proprietary magic that should cost millions of dollars. Anyone can build their own core.

5G Is an Open API Problem

5G core specifications are written by 3GPP, an international standards body. The documents are dense, but fundamentally straightforward. Modern 5G Cores use:

  • RESTful OpenAPI schemas
  • HTTP/2
  • Microservices

In other words, a 5G mobile core may seem familiar to many software engineers.

For example, TS 29.503 defines the UDM service surface directly as OpenAPI Definitions:

  /{supi}/am-data/ecr-data:
    get:
      summary: retrieve a UE's subscribed Enhanced Coverage Restriction Data
      operationId: GetEcrData
      tags:
        - Enhanced Coverage Restriction Data Retrieval
      security:
        - {}
        - oAuth2ClientCredentials:
          - nudm-sdm
        ... etc
      parameters:
        - name: supi
          in: path
          description: Identifier of the UE
          required: true
          schema:
            $ref: 'TS29571_CommonData.yaml#/components/schemas/Supi'
        ...etc
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnhancedCoverageRestrictionData'
          headers:
            Cache-Control:
              description: Cache-Control containing max-age, as described in RFC 9111, 5.2
              schema:
                type: string
            ... etc
        '400':
          $ref: 'TS29571_CommonData.yaml#/components/responses/400'
        ... etc
        default:
          description: Unexpected error

They also provide guidance on each endpoint. Here’s a raw image from the spec:

supi-am-data-ecr-data

there are approx. 20-80 of these endpoints per microservice, and 8 microservices.

This got me thinking: How much of this can I safely offload to AI? If every endpoint is strictly defined, AI can build this if I have a known success condition and solid load testing.

Automated Type Generation

The first thing I discovered were collections of types. For every type used in a 5G mobile core, there is a strict definition down to primitive data types describing how it’s structured. (Example)

PduSessionType:
    anyOf:
    - type: string
        enum:
        - IPV4
        - IPV6
        - IPV4V6
        - UNSTRUCTURED
        - ETHERNET
    - type: string
    description: >
    PduSessionType indicates the type of a PDU session. It shall comply with the provisions defined in table 5.4.3.3-1. 

which translates to Typescript:

export enum PduSessionType {
  IPV4 = "IPV4",
  IPV6 = "IPV6",
  IPV4V6 = "IPV4V6",
  UNSTRUCTURED = "UNSTRUCTURED",
  ETHERNET = "ETHERNET"
}

This is a perfect task for AI- a basic, repetitive task executed hundreds of times. There is no room for error here. Surely enough, Claude was able to one-shot every datatype file with 100% accuracy. Pre-AI, this task would have taken weeks.


Validating the Core

Now that I had the types complete, the next step was creating the API endpoints. This is trickier because there are hundreds of endpoints in the 3gpp specification and connecting to a 5G network involves approximately 20 endpoint calls, with accuracy required down to the byte level.

To verify the implementation, I needed to hook the core up to a phone and a cell tower. I didn't have $10k to spare to spend on a tower, so I used UERANSIM, a mature cell tower simulator, as my "source of truth."

The Development Cycle:

  1. Implement: Create an endpoint based on the 3GPP spec.
  2. Test: Point UERANSIM at the custom 5G core.
  3. Debug: If it failed, use the error logs to refine the code.

I repeated this process until every necessary endpoint was implemented for UERANSIM to attach to the core and remain stable.


Why Does This Matter?

As an engineer, it is important to challenge how existing systems work. This development proves that the existing system is broken and overpriced. The barrier isn't technical complexity. It's access to information and willingness to question vendor lock-in.

This has real implications. If I can create a 5G Mobile Core for free that survives a high-throughput, live environment, it can save cellular companies millions per year.

I'm not suggesting everyone should roll their own production core. Security, reliability, and scale matter enormously in telecom. But the cost gap between what vendors charge and what the technology actually requires is unjustifiable.

What’s Next?

While the core is functional in a lab setting, it needs rigorous testing before it can handle real-world traffic. Mobile cores carry the primary authentication mechanisms for a network; any gap is a massive security risk for personal devices.

The Roadmap to Production:

Milestone Description Cost
Real-World RAN Transition from simulation to a physical Radio/Cell tower. Hardware ($10k+)
Security Audit External pentesting and audit of authentication flows. Pentester ($100k+)
Load Testing Ensuring all microservices can handle high-concurrency production traffic. Unknown

As you can imagine, running a distributed architecture in the cloud can get expensive. The next phase is ensuring the core can take the heat of a real production environment without breaking the bank.